为什么shape.sdo_ordinates(1)在PL/SQL中工作,而在SQL中不起作用?
Oracle 18c:
我可以使用shape.sdo_ordinates(1)
在自定义PL/SQL函数中提取startpoint x坐标:
with
function startpoint_x(shape in sdo_geometry) return number
is
begin
return
shape.sdo_ordinates(1);
end;
select
startpoint_x(shape) as startpoint_x
from
(select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
from dual)
STARTPOINT_X
------------
1
但是,如果我仅在SQL查询中尝试执行此操作,我会得到一个错误:
select
(shape).sdo_ordinates(1) as startpoint_x
from
(select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
from dual)
ORA-00904: "MDSYS"."SDO_GEOMETRY"."SDO_ORDINATES": invalid identifier
对于它的价值,如果我要删除(1),然后选择整个sdo_ordinates
属性,那将有效:
select
(shape).sdo_ordinates as ordinates
from
(select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
from dual)
ORDINATES
------------------------
SDO_ORDINATE_ARRAY(1, 2)
当然,这不是我想要的。我想将开始点X坐标为一个数字。
为什么shape.sdo_ordinates(1)
在PL/SQL中工作,而在SQL查询中不使用?
Oracle 18c:
I can extract the startpoint X coordinate from an SDO_GEOMETRY using SHAPE.SDO_ORDINATES(1)
in a custom PL/SQL function:
with
function startpoint_x(shape in sdo_geometry) return number
is
begin
return
shape.sdo_ordinates(1);
end;
select
startpoint_x(shape) as startpoint_x
from
(select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
from dual)
STARTPOINT_X
------------
1
But if I try do that purely in an SQL query, I get an error:
select
(shape).sdo_ordinates(1) as startpoint_x
from
(select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
from dual)
ORA-00904: "MDSYS"."SDO_GEOMETRY"."SDO_ORDINATES": invalid identifier
For what it's worth, if I were to remove the (1) and instead select the entire sdo_ordinates
attribute, then that would work:
select
(shape).sdo_ordinates as ordinates
from
(select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
from dual)
ORDINATES
------------------------
SDO_ORDINATE_ARRAY(1, 2)
But of course, that's not what I want. I want to get the startpoint X coordinate as a number.
Why does SHAPE.SDO_ORDINATES(1)
work in PL/SQL, but not in an SQL query?
Somewhat related: Get X & Y coordinates from GEOM_SEGMENT_START_PT()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为在SQL中不支持根据索引提取收集元素的语法。它不仅是SDO对象,而且是任何集合:
输出:
和:
输出:
(我认为这意味着它试图将其解析为函数,但错误消息
的 帮助/明显不如前面。)由于您需要使用表集合表达式解释整个集合,然后过滤以获取所需的行:
db<> fiddle 在这里
Because the syntax of extracting collection elements by index is not supported in SQL. It is not just SDO objects but any collection:
Outputs:
and:
Outputs:
(Which, I think means that it is trying to parse it as a function but the error message is less helpful/obvious than the previous one.)
There are methods of getting the value but it is more complicated as you need to dereference the entire collection using a table collection expression and then filter to get the desired row:
db<>fiddle here
我的猜测是,Varrays和Table Collections必须被视为表,而SQL(3)不支持本机SQL。
My guess is that varrays and table collections have to be treated as tables, and SQL (3) doesn't support them in native SQL.
看看这样的解决方法是否有帮助...
这是您拥有的,它有效:
这是您尝试的,但它不起作用:
这是解决方案:
See if such a workaround helps ...
This is what you have and it works:
This is what you tried, but it doesn't work:
And this is a workaround: