Skip to content
Advertisement

Generate rows from JSON (SDO_GEOMETRY)

I have a multi-part SDO_GEOMETRY that I can represent as JSON (Oracle 21c):


As an experiment, I want to find a way to generate rows from the JSON:

Each row is a vertex of the geometry.

Question:

In an SQL query, is there a way to generate rows for each of the JSON vertices?


I’m aware that SDO_GEOMETRY has a GetVertices() function that can be used for this — it avoids the JSON step. That works, but in my case, I want to experiment with parsing vertices out of JSON text using SQL. If I find something that works, I want to use that same JSON extraction technique on a user-defined datatype that doesn’t have a GetVertices function.

Advertisement

Answer

The simplest method (adapted from my answer to your previous question for 3D lines) is to use SDO_GEOMETRY and not to use JSON functions:

But, if you assume that you are only working with 2D multi-lines (GTYPE = 2006) then you can get the output with JSON but its not simple:

Which both output:

LINE_ID ELEM_NO COORD_ID X Y
001 1 1 0 5
001 1 2 10 10
001 1 3 30 0
001 2 1 50 10
001 2 2 60 10

db<>fiddle here

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