You could:
- Create an external table to read the file
- Use JSON_table to convert the document to relational rows-and-columns
Which looks a little like:
/* Create the file */
create or replace directory tmp as '/tmp';
declare
f utl_file.file_type;
begin
f := utl_file.fopen ('TMP', 'input.json', 'w');
utl_file.put_line ( f, '{ "CAR":["%HON%","%UZU%"], "NAME":["%RAY%","%OE%"] }');
utl_file.fclose(f);
end;
/
create table json_ext (
json_doc varchar2(100)
) organization external (
default directory tmp
access parameters (
records delimited by newline
fields (
json_doc char(1000)
)
)
location ( 'input.json' )
);
select * from json_ext;
JSON_DOC
{ "CAR":["%HON%","%UZU%"], "NAME":["%RAY%","%OE%"] }
select *
from json_ext,
json_table (
json_doc, '$'
columns (
nested path '$.CAR[*]' columns (
CAR path '$'
),
nested path '$.NAME[*]' columns (
NAME path '$'
)
)
);
JSON_DOC CAR NAME
{ "CAR":["%HON%","%UZU%"], "NAME":["%RAY%","%OE%"] } %HON% <null>
{ "CAR":["%HON%","%UZU%"], "NAME":["%RAY%","%OE%"] } %UZU% <null>
{ "CAR":["%HON%","%UZU%"], "NAME":["%RAY%","%OE%"] } <null> %RAY%
{ "CAR":["%HON%","%UZU%"], "NAME":["%RAY%","%OE%"] } <null> %OE%
This splits each array into its own set of rows and columns. To get this as a single list of attribute names and array values, you can unpivot the results:
with rws as (
select j.*
from json_ext,
json_table (
json_doc, '$'
columns (
nested path '$.CAR[*]' columns (
CAR path '$'
),
nested path '$.NAME[*]' columns (
NAME path '$'
)
)
) j
)
select * from rws
unpivot (
val for attr in ( CAR, NAME )
);
ATTR VAL
CAR %HON%
CAR %UZU%
NAME %RAY%
NAME %OE%