我只需要在 Oracle sdo_nn 更新语句中有一个唯一的结果,

I need only one unique result in Oracle sdo_nn Update sentence ,

我只需要一个从 tableB.Field 到 tableA.Field 的唯一结果 我正在使用 sdo 运算符 sdo_nn,这是代码:

UPDATE table1 t1
SET t1.fieldA = (SELECT T2.fieldB,SDO_NN_DISTANCE(1) distance
FROM table1 T1, table2 T2
WHERE 
(sdo_nn(t1.geometry,t2.geometry,'SDO_NUM_RES=1',1)= 'TRUE')
ORDER BY DIST
)
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 = NULL
     );

在子查询的select语句中出现错误,因为我只使用了一个字段(t1.fieldA),但在语句中我使用了运算符SDO_NN_DISTANCE(1) 和 sql 开发人员将此运算符视为另一个字段。这句话的正确写法是什么?我只使用 sql 因为我需要在 vba

中插入此代码

谢谢!!!

显然,你不能(简化)

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

因此,从使用分析函数(row_number)的子查询中单独获取fieldB,以按sdo_nn_distance(1) desc“排序”行;然后获取第一行的 fieldB 值。

类似这样的事情(我希望我把括号写对了):

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);