MDSYS.ST_GEOMETRY; Oracle 18c:
The following query works. It extracts the first point from an MDSYS.ST_GEOMETRY:
--Source: https://www.spdba.com.au/using-oracles-st_geometry-type-hierarchy-with-sdo_geometry-st_pointn-and-st_numpoints/
with cte as (
select treat(mdsys.st_geometry.from_wkt('LINESTRING(10 10, 20 20)',26917) as mdsys.st_linestring) as shape
from dual
)
select
(shape).st_pointn(1) as first_point
from
cte
Result:
MDSYS.ST_POINT(MDSYS.SDO_GEOMETRY(2001, 26917, MDSYS.SDO_POINT_TYPE(10, 10, NULL), NULL, NULL))
I don't understand why we need to Treat()
the ST_GEOMETRY supertype as an ST_LINESTRING subtype in order to use ST_PointN()
to get the point.
For example, if I remove the Treat(... as ST_LINESTRING)
, then I get an error:
with cte as (
select mdsys.st_geometry.from_wkt('LINESTRING(10 10, 20 20)',26917) as shape
from dual
)
select
(shape).st_pointn(1) as first_point
from
cte
Error:
ORA-00904: "MDSYS"."ST_GEOMETRY"."ST_POINTN": invalid identifier
Why do I get that error when I remove Treat()
?