为什么(shape).sdo_ordinates(1)语法失败,而(shape).st_pointn(1)成功?

发布于 2025-02-08 21:58:48 字数 1249 浏览 1 评论 0原文

Oracle 18c:


在一个相关问题中,我们确定了:

不支持根据索引提取收集元素的语法 在SQL。

因此,使用此语法的查询将失败:(shape).sdo_ordinates(1)

select
  (shape).sdo_ordinates(1) as startpoint_x
from
  (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape 
   from dual)

Error:
ORA-00904: "MDSYS"."SDO_GEOMETRY"."SDO_ORDINATES": invalid identifier

来源:为什么shape.sdo_ordinates(1)在pl/sql中工作,而在sql?


但是,我有一个查询相似的(不同的数据类型),当我使用看似相似的语法时会成功:(shape).st_pointn(1)

select
  (shape).st_pointn(1) as startpoint
from
  (select treat(st_geometry.from_wkt('Linestring(1 2, 3 4, 5 6)',26917) as st_linestring) as shape
   from dual)

Result:
MDSYS.ST_POINT(MDSYS.SDO_GEOMETRY(2001, 26917, MDSYS.SDO_POINT_TYPE(1, 2, NULL), NULL, NULL))

资料来源:为什么我们需要将()mdsys.st_ geometry视为st_linestring来使用st_pointn(1)?


为什么(shape).sdo_ordinates(1)形状).st_pointn(1)成功?

Oracle 18c:


In a related question, we determined:

The syntax of extracting collection elements by index is not supported
in SQL.

So a query that uses this syntax will fail: (shape).sdo_ordinates(1),

select
  (shape).sdo_ordinates(1) as startpoint_x
from
  (select sdo_geometry('linestring(1 2, 3 4, 5 6)') as shape 
   from dual)

Error:
ORA-00904: "MDSYS"."SDO_GEOMETRY"."SDO_ORDINATES": invalid identifier

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


However, I have a query that is similar (different datatype) that succeeds when I use seemingly similar syntax: (shape).st_pointn(1).

select
  (shape).st_pointn(1) as startpoint
from
  (select treat(st_geometry.from_wkt('Linestring(1 2, 3 4, 5 6)',26917) as st_linestring) as shape
   from dual)

Result:
MDSYS.ST_POINT(MDSYS.SDO_GEOMETRY(2001, 26917, MDSYS.SDO_POINT_TYPE(1, 2, NULL), NULL, NULL))

Source: Why do we need to Treat() MDSYS.ST_GEOMETRY as ST_LINESTRING to use ST_PointN(1)?


Why does (SHAPE).SDO_ORDINATES(1) fail, but (SHAPE).ST_PointN(1) succeeds?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

清泪尽 2025-02-15 21:58:48

[tl; dr]

sdo_ordinatesmdsys.sdo_geometry数据类型的集合属性。

st_pointn是(mdsys.st_linestring data类型)的(超级类型)的成员函数。


当您使用时:

select sdo_geometry('linestring(1 2, 3 4, 5 6)').sdo_ordinates(1)
from   dual

然后,它以object_type.member_function(gright)的形式将SQL引擎处理语法作为对成员函数的调用,并且没有sdo_ordinates成员> sdo_geometry数据类型,输出为:

  ora-00904:“ mdsys”。“ sdo_geometry”。“ sdo_ordinates”:无效的标识符
 

因为没有sdo_ordinates成员函数在mdsys.sdo_geometry对象上。


相反,如果您使用:

select (sdo_geometry('linestring(1 2, 3 4, 5 6)').sdo_ordinates)(1)
from   dual

然后SQL引擎将语法作为(object_type.collection_attribute)(index)进行处理:输出为:

  ora-03001:未完成功能
 

因为提取收集元素在SQL中不支持。


最后:

select treat(
         st_geometry.from_wkt('Linestring(1 2, 3 4, 5 6)',26917)
         as st_linestring
       ).st_pointn(1)
from   dual

返回st_linestring对象类型,然后使用参数1调用st_pointn成员函数。之所以起作用,是因为在mdsys.st_curve上有一个st_pointn成员函数,它是mdsys.st_linestring的超级类型。

您可以使用以下方式看到对象的源:

select text
from   all_source
where  type  = 'TYPE'
and    owner = 'MDSYS'
and    name  = 'ST_LINESTRING'
ORDER BY line

然后,因为它的父:

select text
from   all_source
where  type  = 'TYPE'
and    owner = 'MDSYS'
and    name  = 'ST_CURVE'
ORDER BY line

包括声明:

db<

[TL;DR]

SDO_ORDINATES is a collection attribute of the MDSYS.SDO_GEOMETRY data type.

ST_POINTN is a member function of (a super-type of) the MDSYS.ST_LINESTRING data type.


When you use:

select sdo_geometry('linestring(1 2, 3 4, 5 6)').sdo_ordinates(1)
from   dual

Then it the SQL engine processes the syntax as a call to a member function in the form of object_type.member_function(argument) and there is no SDO_ORDINATES member function of the SDO_GEOMETRY data type and the output is:

ORA-00904: "MDSYS"."SDO_GEOMETRY"."SDO_ORDINATES": invalid identifier

Because there is no SDO_ORDINATES member function on the MDSYS.SDO_GEOMETRY object.


If instead, you use:

select (sdo_geometry('linestring(1 2, 3 4, 5 6)').sdo_ordinates)(1)
from   dual

Then the SQL engine processes the syntax as (object_type.collection_attribute)(index) and the output is:

ORA-03001: unimplemented feature

Because extracting collection elements is not supported in SQL.


Finally:

select treat(
         st_geometry.from_wkt('Linestring(1 2, 3 4, 5 6)',26917)
         as st_linestring
       ).st_pointn(1)
from   dual

Returns an ST_LINESTRING object type and then you call the ST_POINTN member function with the argument 1. This works because there is a ST_POINTN member function declared on MDSYS.ST_CURVE which is the super-type of MDSYS.ST_LINESTRING.

You can see the object's source using:

select text
from   all_source
where  type  = 'TYPE'
and    owner = 'MDSYS'
and    name  = 'ST_LINESTRING'
ORDER BY line

and then, for it's parent:

select text
from   all_source
where  type  = 'TYPE'
and    owner = 'MDSYS'
and    name  = 'ST_CURVE'
ORDER BY line

Which includes the declaration:

 MEMBER FUNCTION ST_PointN(aposition INTEGER) RETURN ST_Point DETERMINISTIC,

db<>fiddle here

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