I have a table which has CLOB data type. Value of the column is actually JSON data.
{"ClassId":32000,"Attributes":
[
{"Name":"ID","Value":"4548"},
{"Name":"HREF","Value":"-1"},
{"Name":"HPRECISION","Value":"5"},
{"Name":"HMETHOD","Value":"96"},
{"Name":"GEO-METHOD","Value":"96"},
{"Name":"GEO-PRECISION","Value":"5"},
{"Name":"GEO-VISIBILITY","Value":"0"}
]
}
{"ClassId":30074,"Attributes":
[
{"Name":"ID","Value":"265794"},
{"Name":"HREF","Value":"-1"},
{"Name":"HPRECISION","Value":"5"},
{"Name":"HMETHOD","Value":"100"},
{"Name":"GEO-METHOD","Value":"90"},
{"Name":"GEO-PRECISION","Value":"5"},
{"Name":"GEO-VISIBILITY","Value":"0"}
]
}
If I select the table table it will show like this
I need to parse the data so that I can get the output of HMETHODE and HPRECISION.
Classid ID HREF HPRECISION HMETHOD
30074 265794 -1 5 96
32000 4548 -1 5 100
or may be the output will be like below
I was trying several method but getting either error or no data found. If anyone can fix this sql it would be very helpful.
select ClassId, NAME, VALUE
from importitem D,
JSON_TABLE
(
D.JSON_DATA, '$' COLUMNS
(
ClassId NUMBER path '$.ClassId',
NESTED path '$.Attributes[*]' COLUMNS
(
NAME NUMBER PATH '$.Namne',
Value NUMBER PATH '$.Value'
)
)
) J ;
Or may be like this, i have tried two different way.
SELECT *
FROM JSON_TABLE(
'{"ClassId":30074,
"Attributes":
[
{"Name":"ID","Value":"356605"},
{"Name":"HREF","Value":"-1"},
{"Name":"HPRECISION","Value":"5"},
{"Name":"HMETHOD","Value":"96"},
{"Name":"GEO-METHOD","Value":"96"},
{"Name":"GEO-PRECISION","Value":"5"},
{"Name":"GEO-VISIBILITY","Value":"0"}
]
}',
'$.Attributes'
COLUMNS
ID NUMBER PATH '$.Namne.Value',
HREF NUMBER PATH '$.Namne.Value',
HPRECISION NUMBER PATH '$.Namne.Value',
HMETHOD NUMBER PATH '$.Namne.Value'
);