Skip to content
Advertisement

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

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),

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).

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?

Advertisement

Answer

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

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:

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


If instead, you use:

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

Because extracting collection elements is not supported in SQL.


Finally:

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:

and then, for it’s parent:

Which includes the declaration:

db<>fiddle here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement