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