3

如果我运行以下查询:

select B3.bid as id ,B3.bshape as shape 
from Buildings B3 
where B3.bid in 
(
   select distinct B1.bid from Buildings B1, 
   (
     select * from Buildings B where B.bname in (select BOF.bname from Buildings_On_Fire BOF)
   ) B2 where sdo_nn(B1.bshape, B2.bshape, 'distance=100') = 'TRUE' and B1.bname != b2.bname
)



我收到以下错误:

第 1 行的错误:
ORA-13249:不使用索引就无法评估 SDO_NN
ORA-06512:在“MDSYS.MD”,第 1723 行
ORA-06512:在“MDSYS.MDERR”,第 17行 ORA-06512:在“MDSYS.MD”
。 PRVT_IDX”,第 9 行


但是,如果只运行以下子查询:

select distinct B1.bid from Buildings B1, 
(
   select * from Buildings B  where B.bname in (select BOF.bname from Buildings_On_Fire BOF)
) B2 where sdo_nn(B1.bshape, B2.bshape, 'distance=100') = 'TRUE' and B1.bname != b2.bname


这执行得很好。我已经验证了空间索引,它们似乎是有效的。
我是 Oracle 新手,不知道下一步该做什么。请帮忙。

如果有不需要更改上述查询的解决方案,那将是最好的。

4

1 回答 1

1

A bit late for an answer, but here comes ...

The error you get is because the optimizer did not use the spatial index to solve the SDO_NN operator. Contrary to the other spatial operators (SDO_RELATE, SDO_WIHIN_DISTANCE), SDO_NN cannot be resolved without the help of the index.

Then again I suspect your query is incorrectly formulated. If I understand correctly, what you want to do is find all buildings that are within a distance of 100 (what ? meters ?) from any building that is on fire. For that, use the SDO_WITHIN_DISTANCE operator.

Let's assume your tables are like this:

buildings (bid number, bname varchar2(30), bshape sdo_geometry)

buildings_on_fire (bid number, bname varchar2(30))

The select will then be like this:

select b1.bid as id, b1.bshape as shape
from   buildings b1, 
       buildings b2, 
       buildings_on_fire bof
where  b2.bname = bof.bname
and    b1.bname <> b2.bname
and    sdo_within_distance (
         b1.bshape, b2.bshape, 
         'distance=100 unit=meter'
       ) = 'TRUE';
于 2013-10-18T14:33:01.417 回答