Question

I've been struggling to create an Oracle SQL query that will tell me if my SDO table contains curves or arcs. I know that the sdo_elem_info contains the information I need, but I don't know how to use SQL to separate out the etype and interpretation from the sdo_elem_info.

So far, all I have is: select tbl.shape.sdo_elem_info from my_table tbl

Was it helpful?

Solution

You can use the TABLE function to extract the sdo_elem_info_array elements, then pivot that and aggregate the resulting rows to yield a row per element, with a column for offset, etype and interpretation.

Something like this should give you your query... (warning: untested)

WITH elem_info AS (
  SELECT 
    TRUNC((ROWNUM - 1) / 3, 0) element_no
  , MAX(DECODE(MOD(ROWNUM, 3), 1, t.COLUMN_VALUE, NULL)) offset
  , MAX(DECODE(MOD(ROWNUM, 3), 2, t.COLUMN_VALUE, NULL)) etype
  , MAX(DECODE(MOD(ROWNUM, 3), 0, t.COLUMN_VALUE, NULL)) interpretation
  FROM my_table tbl
  , TABLE(tbl.shape.sdo_elem_info) t
  GROUP BY TRUNC((ROWNUM - 1) / 3, 0)
)
SELECT DECODE(COUNT(*), 0, 'false', 'true')
FROM elem_info ei
WHERE ei.etype IN (1005, 2005) 
OR ei.interpretation IN (2, 4)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top