为什么shape.sdo_ordinates(1)在PL/SQL中工作,而在SQL中不起作用?

发布于 2025-02-06 02:23:21 字数 1490 浏览 2 评论 0原文

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)

db<> fiddle

当然,这不是我想要的。我想将开始点X坐标为一个数字。

为什么shape.sdo_ordinates(1)在PL/SQL中工作,而在SQL查询中不使用?


有点相关: get x& y geom_segment_start_pt()y坐标

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)

db<>fiddle

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掌心的温暖 2025-02-13 02:23:21

为什么shape.sdo_ordinates(1)在PL/SQL中工作,而在SQL查询中不使用?

因为在SQL中不支持根据索引提取收集元素的语法。它不仅是SDO对象,而且是任何集合:

SELECT SYS.ODCIVARCHAR2LIST('a', 'b', 'c')(1) FROM DUAL;

输出:

  ORA-03001:未完成功能
 

和:

SELECT l.list(1)
FROM   (SELECT SYS.ODCIVARCHAR2LIST('a', 'b', 'c') AS list FROM DUAL) l;

输出:

  ora-00904:“ l”。“列表”:无效标识符
 

(我认为这意味着它试图将其解析为函数,但错误消息


的 帮助/明显不如前面。)由于您需要使用表集合表达式解释整个集合,然后过滤以获取所需的行:

SELECT (
         SELECT COLUMN_VALUE
         FROM   TABLE(s.shape.sdo_ordinates)
         FETCH FIRST ROW ONLY
       ) as startpoint_x
FROM  (
  select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape from dual
) s

db&lt;&gt; fiddle 在这里

Why does SHAPE.SDO_ORDINATES(1) work in PL/SQL, but not in an SQL query?

Because the syntax of extracting collection elements by index is not supported in SQL. It is not just SDO objects but any collection:

SELECT SYS.ODCIVARCHAR2LIST('a', 'b', 'c')(1) FROM DUAL;

Outputs:

ORA-03001: unimplemented feature

and:

SELECT l.list(1)
FROM   (SELECT SYS.ODCIVARCHAR2LIST('a', 'b', 'c') AS list FROM DUAL) l;

Outputs:

ORA-00904: "L"."LIST": invalid identifier

(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:

SELECT (
         SELECT COLUMN_VALUE
         FROM   TABLE(s.shape.sdo_ordinates)
         FETCH FIRST ROW ONLY
       ) as startpoint_x
FROM  (
  select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape from dual
) s

db<>fiddle here

黒涩兲箜 2025-02-13 02:23:21

我的猜测是,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.

凯凯我们等你回来 2025-02-13 02:23:21

看看这样的解决方法是否有帮助...

这是您拥有的,它有效:

SQL> select
  2    (shape).sdo_ordinates as ordinates
  3  from
  4    (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
  5     from dual);

ORDINATES
------------------------------------------------------------
SDO_ORDINATE_ARRAY(1, 2, 3, 4, 5, 6)

这是您尝试的,但它不起作用:

SQL> select
  2    (shape).sdo_ordinates(1) as startpoint_x
  3  from
  4    (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
  5     from dual);
  (shape).sdo_ordinates(1) as startpoint_x
                       *
ERROR at line 2:
ORA-00904: "MDSYS"."SDO_GEOMETRY"."SDO_ORDINATES": invalid identifier

这是解决方案

SQL> select
  2    sdo_geom.sdo_min_mbr_ordinate(shape, 1) as startpoint_x
  3  from
  4    (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
  5     from dual);

STARTPOINT_X
------------
           1

SQL>

See if such a workaround helps ...

This is what you have and it works:

SQL> select
  2    (shape).sdo_ordinates as ordinates
  3  from
  4    (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
  5     from dual);

ORDINATES
------------------------------------------------------------
SDO_ORDINATE_ARRAY(1, 2, 3, 4, 5, 6)

This is what you tried, but it doesn't work:

SQL> select
  2    (shape).sdo_ordinates(1) as startpoint_x
  3  from
  4    (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
  5     from dual);
  (shape).sdo_ordinates(1) as startpoint_x
                       *
ERROR at line 2:
ORA-00904: "MDSYS"."SDO_GEOMETRY"."SDO_ORDINATES": invalid identifier

And this is a workaround:

SQL> select
  2    sdo_geom.sdo_min_mbr_ordinate(shape, 1) as startpoint_x
  3  from
  4    (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape
  5     from dual);

STARTPOINT_X
------------
           1

SQL>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文