ORACLE - JSON到键值对表(ORACLE - JSON To Key Value Pair Table)
有没有办法从CLOB Json列获取具有键/值对的表?
这里的想法是以动态的方式获得这些价值。 因为CLOB列并不总是包含相同的结构。
我已经创建了一个执行此操作的函数,但是因为它实际上解析了json字符串,所以当我们在具有许多记录的表中使用它时它非常慢。 而且速度非常慢,我的意思是每秒2-5条记录,我知道这很糟糕。
Oracle工具(v.12c)没有提供获取json标记/值的动态方法,我们总是指定路径。
我一直在四处挖掘,没有任何运气。 有什么想法吗?
Is there any way to obtain a table with key/value pairs from a CLOB Json Column?
The idea here is to get these values, on a dynamic way. Because the CLOB column does not always contain the same structure.
I've created a function that does this, however since it literally parses the json string, when we use it in a table with many records its very slow. And by very slow I mean like 2-5 records per second, i know it's terrible.
The Oracle tools (v.12c) do not provide a dynamic way to obtain the json tags/values, we have always to specify the paths.
I've been digging all around without any luck. Any thoughts?
原文:https://stackoverflow.com/questions/42702150
2020-03-05 15:03
满意答案
12.2包含一组PL / SQL对象,可用于构建类似JSON文档结构的DOM。 然后,您可以使用对象上的方法提取密钥列表等。 查看12.2 doc中的JSON_OBJECT_T,JSON_ARRAY_T等,可以像这样使用..
SQL> create or replace type NV_PAIR_T as object (
2 NAME VARCHAR2(32),
3 VALUE VARCHAR2(32)
4 )
5 /
Type created.
SQL> create or replace type NV_PAIR_TABLE as TABLE of NV_PAIR_T
2 /
Type created.
SQL> create or replace function GET_KEY_VALUES(P_JSON_DOC VARCHAR2)
2 return NV_PAIR_TABLE PIPELINED
3 as
4 JO JSON_OBJECT_T := JSON_OBJECT_T(P_JSON_DOC);
5 JO_KEYS JSON_KEY_LIST := JO.get_keys();
6 begin
7
8 for i in 1..JO_KEYS.count loop
9 pipe row (NV_PAIR_T(JO_KEYS(i),JO.get_string(JO_KEY