sql >> Base de Datos >  >> RDS >> Oracle

Solo necesito un resultado único en la oración de actualización Oracle sdo_nn,

Obviamente, no puedes (simplificado)

set t1.fieldA = (t2.fieldB, distance)  --> you want to put two values into a single column

Por lo tanto, obtenga fieldB solo de la subconsulta que usa la función analítica (row_number ) para "ordenar" filas por sdo_nn_distance(1) desc; luego obtenga el fieldB de la primera fila valor.

Algo como esto (espero haber puesto bien el paréntesis):

UPDATE table1 t1
   SET t1.fieldA =
          (SELECT x.fieldB                                 --> only fieldB
             FROM (SELECT T2.fieldB,                       --> from your subquery
                          SDO_NN_DISTANCE (1) distance,
                          ROW_NUMBER ()
                             OVER (ORDER BY sdo_nn_distance (1) DESC) rn
                     FROM table1 T1, table2 T2
                    WHERE (sdo_nn (t1.geometry,
                                   t2.geometry,
                                   'SDO_NUM_RES=1',
                                   1) = 'TRUE')) x
            WHERE rn = 1)                                  --> where RN = 1
 WHERE EXISTS
          (SELECT 1
             FROM table2 t2
            WHERE     sdo_nn (t1.geometry,
                              t2.geometry,
                              'SDO_NUM_RES=1',
                              1) = 'TRUE'
                  AND (   t2.cell_name = 'string1'
                       OR t2.cell_name = 'string2')
                  AND t1.fieldA IS NULL);