[ad_1]
[*]
I have a json element with this structure
obj_type
-_1,-start - end -_2, -start -end -_3, -start -end
I would like to obtain a table like this
| obj_type | 1_start| 1_end | 2_start | 2_end | 3_start | 3_end |
| _1 |
| _2 | ………………………………… value………….
| _3 |
WITH d (department_data) AS (SELECT (UTL_RAW.cast_to_raw ('{
"r": [
{
"obj_type": "A",
"_1": {
"start": "1",
"end": "2"
},
"_2": {
"start": "15",
"end": "25"
},
"_3": {
"start": "26",
"end": "33"
}
},
{
"obj_type": "B",
"_1": {
"start": "1",
"end": "2"
},
"_2": {
"start": "3",
"end": "12"
}
}, {
"obj_type": "C",
"_2":{
"start": "1",
"end": "2"
}
}, {
"obj_type": "D",
"_3": {
"start": "",
"end": "2"
}
}
]
}')) FROM DUAL)
--select * from d;
SELECT j.*
FROM d,
JSON_TABLE (
d.department_data,
'$'
COLUMNS (
NESTED PATH '$.r[*]'
COLUMNS (
name PATH '$.obj_type',
NESTED PATH '$._1[*]'
columns ("_1_start" PATH '$.start',
"_2_end" PATH '$.end'),
NESTED PATH '$."_2"[*]'
columns ("UVG_start" PATH '$.start',
"UVG - Zusatz_end" PATH '$.end'),
NESTED PATH '$."_3"[*]'
columns ("UVG - Ueberschusslohn_start" PATH '$.start',
"UVG - Ueberschusslohn_end" PATH '$.end')
))) j
This query is not returning what I’ve expected.
The lines are duplicated. start and end from _1 are not the same line of start and end from _2.
Furthermore if there is no value they are not printed.
[*][ad_2]
[*]