在 oracle 中使用带有空间查询的 exists 会导致错误
Using a exists with a spatial query in oracle results in an error
我尝试查询彼此之间距离在 130 公里以内的所有项目。
如果我在 where 部分使用 exists 我会得到一个异常:
这很好用:
select *
from tbl_geometry g1, tbl_geometry g2
where sdo_within_distance(g1.GEOMETRY, g2.GEOMETRY, 'distance=130 unit=km')='TRUE'
and g1.id <> g2.id;
这里我得到一个例外:
select *
from tbl_geometry g1
where exists(
select *
from tbl_geometry g3
where g1.id <> g3.id
and sdo_within_distance(g1.GEOMETRY, g3.GEOMETRY, 'distance=130 unit=km') = 'TRUE'
);
错误:
[72000][13226] ORA-13226:没有空间索引不支持接口 ORA-06512:在“MDSYS.MD”,第 1723 行 ORA-06512:在“MDSYS.MDERR”,第 8 行 ORA- 06512:在“MDSYS.SDO_3GL”,第 1052 行
添加 tbl_geometry 的另一个实例“解决”了问题:
select *
from tbl_geometry g1
where exists(
select *
from tbl_geometry g2, tbl_geometry g3
where g2.id = g1.id
and g2.id <> g3.id
and sdo_within_distance(g2.GEOMETRY, g3.GEOMETRY, 'distance=130 unit=km') = 'TRUE'
);
知道如何在没有 2 tbl_geometry 的情况下使用 exists 吗?
谢谢。
想看一些魔法吗?
您的查询:
SQL> SELECT COUNT(*)
2 FROM tbl_geometry g1
3 WHERE EXISTS
4 (SELECT *
5 FROM tbl_geometry g3
6 WHERE g1.id <> g3.id
7 AND sdo_within_distance (g1.geometry,
8 g3.geometry,
9 'distance=130 unit=km') = 'TRUE');
SELECT COUNT(*)
*
ERROR at line 1:
ORA-13226: interface not supported without a spatial index
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 8
ORA-06512: at "MDSYS.SDO_3GL", line 1082
我的查询:
SQL> SELECT COUNT(*)
2 FROM tbl_geometry g1
3 WHERE EXISTS
4 (SELECT *
5 FROM tbl_geometry g3
6 WHERE g1.id <> g3.id
7 AND sdo_within_distance (g3.geometry,
8 g1.geometry,
9 'distance=130 unit=km') = 'TRUE');
COUNT(*)
----------
815
SQL>
你能看出区别吗?不?这是:
7 AND sdo_within_distance (g1.geometry, --> g1
8 g3.geometry, --> g3
9 'distance=130 unit=km') = 'TRUE');
对比
7 AND sdo_within_distance (g3.geometry, --> g3
8 g1.geometry, --> g1
9 'distance=130 unit=km') = 'TRUE');
为什么?我不知道。但它有效。
我尝试查询彼此之间距离在 130 公里以内的所有项目。 如果我在 where 部分使用 exists 我会得到一个异常:
这很好用:
select *
from tbl_geometry g1, tbl_geometry g2
where sdo_within_distance(g1.GEOMETRY, g2.GEOMETRY, 'distance=130 unit=km')='TRUE'
and g1.id <> g2.id;
这里我得到一个例外:
select *
from tbl_geometry g1
where exists(
select *
from tbl_geometry g3
where g1.id <> g3.id
and sdo_within_distance(g1.GEOMETRY, g3.GEOMETRY, 'distance=130 unit=km') = 'TRUE'
);
错误: [72000][13226] ORA-13226:没有空间索引不支持接口 ORA-06512:在“MDSYS.MD”,第 1723 行 ORA-06512:在“MDSYS.MDERR”,第 8 行 ORA- 06512:在“MDSYS.SDO_3GL”,第 1052 行
添加 tbl_geometry 的另一个实例“解决”了问题:
select *
from tbl_geometry g1
where exists(
select *
from tbl_geometry g2, tbl_geometry g3
where g2.id = g1.id
and g2.id <> g3.id
and sdo_within_distance(g2.GEOMETRY, g3.GEOMETRY, 'distance=130 unit=km') = 'TRUE'
);
知道如何在没有 2 tbl_geometry 的情况下使用 exists 吗?
谢谢。
想看一些魔法吗?
您的查询:
SQL> SELECT COUNT(*)
2 FROM tbl_geometry g1
3 WHERE EXISTS
4 (SELECT *
5 FROM tbl_geometry g3
6 WHERE g1.id <> g3.id
7 AND sdo_within_distance (g1.geometry,
8 g3.geometry,
9 'distance=130 unit=km') = 'TRUE');
SELECT COUNT(*)
*
ERROR at line 1:
ORA-13226: interface not supported without a spatial index
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 8
ORA-06512: at "MDSYS.SDO_3GL", line 1082
我的查询:
SQL> SELECT COUNT(*)
2 FROM tbl_geometry g1
3 WHERE EXISTS
4 (SELECT *
5 FROM tbl_geometry g3
6 WHERE g1.id <> g3.id
7 AND sdo_within_distance (g3.geometry,
8 g1.geometry,
9 'distance=130 unit=km') = 'TRUE');
COUNT(*)
----------
815
SQL>
你能看出区别吗?不?这是:
7 AND sdo_within_distance (g1.geometry, --> g1
8 g3.geometry, --> g3
9 'distance=130 unit=km') = 'TRUE');
对比
7 AND sdo_within_distance (g3.geometry, --> g3
8 g1.geometry, --> g1
9 'distance=130 unit=km') = 'TRUE');
为什么?我不知道。但它有效。