json to db

create table pljson_table_test (num number not null, col clob);
insert into pljson_table_test values(1,
'{"data":
{
"name": "name 1",
"description": "Cloud computing can support a company''s speed and agility, ...",
"type": "link",
"created_time": "2015-05-12T16:26:12+0000",
"shares": { "count": 1 },
"extra": "x1",
"maps" : [ true ]
}
}');

select num, name, map, count
from pljson_table_test,
table(
pljson_table.json_table( --需要解析的表
col,
pljson_varray('data.name', 'data.extra', 'data.maps', 'data.shares.count', 'data.missing'), --指定需要的解析的KEY值
pljson_varray('name', 'extra', 'map', 'count', 'whatelse')) --解析出来之后的字段别名
)
order by num

declare
list_value json_list := json_list('[{"code":"1","status":1},{"code":"2","status":0},{"code":"3","status":0},{"code":"4","status":0}]');
code_value varchar(10);
status_value int(2);
begin
dbms_output.put_line('Count = '||list_value.count);
for i in 1 .. list_value.count
loop
code_value := pljson_ext.get_string(json(list_value.get(i)),'code');
status_value := pljson_ext.get_number(json(list_value.get(i)),'status');
dbms_output.put_line('code = ' || code_value || '; status = ' || status_value );
end loop;
end;
/

你可能感兴趣的:(json to db)