I need help in extracting data from JSON column stored in oracle table. JSON Data column can have maximum of 10 keys and can keys count can vary from 1-10. I have to create view in relational table format using column names stored in metadata table and create dynamic query that reads column data.
CREATE TABLE json_species
(
id NUMBER NOT NULL PRIMARY KEY,
info CLOB CONSTRAINT is_json CHECK (info IS JSON ) )
/
CREATE TABLE json_species_props
(
Props varchar(100)
)
BEGIN
INSERT INTO json_species
VALUES (1, '{"name":"Spider"}');
INSERT INTO json_species
VALUES (2, '{"name":"Elephant", "trunk_length":"10"}');
INSERT INTO json_species
VALUES (3, '{"name":"Shark", "fin_count":"4"}');
Insert into json_species_props values ('name')
Insert into json_species_props values ('trunk_length')
Insert into json_species_props values ('fincount')
COMMIT;
END;
I need output in below relational format
Name Trunk_length fincount
Spider NULL NULL
Elephant 10 NULL
Shark NULL 4
Please guide as I am new to JSON data extraction