[英]How to get the structure of json element?
does a function exist (or how to create such a function) that take a json element and return the structure.是否存在接受 json 元素并返回结构的函数(或如何创建这样的函数)。
For instance, I would like a function f that in this case :例如,在这种情况下,我想要一个函数 f :
SELECT f(json_Array (json_object ('a' VALUE 1,json_Array (b valuejson_object ('a' VALUE 1)))= FROM DUAL;
returns [a integer, b [ a integer]] or somethings equivalent返回 [a integer, b [a integer]] 或等价的东西
From Oracle 12.2, You can use JSON_DATAGUIDE
:从 Oracle 12.2 开始,您可以使用
JSON_DATAGUIDE
:
WITH table_name (value) AS (
SELECT json_Array(
json_object (
'a' VALUE 1,
'b' VALUE json_Array(
json_object ('a' VALUE 1),
'abcd',
123
)
)
)
FROM DUAL
)
SELECT j.path,
j.type
FROM table_name t
CROSS JOIN LATERAL(
SELECT JSON_DATAGUIDE(t.value) AS data
FROM DUAL
) d
CROSS JOIN LATERAL(
SELECT *
FROM JSON_TABLE(
d.data,
'$[*]'
COLUMNS(
path VARCHAR2(200) PATH '$."o:path"',
type VARCHAR2(200) PATH '$.type',
len INTEGER PATH '$."o:length"'
)
)
) j;
Which outputs:哪个输出:
PATH 小路
TYPE 类型
$ $
array 大批
$.a $.a
number 数字
$.b $.b
array 大批
$.b[*] $.b[*]
string 细绳
$.ba $.ba
number 数字
If you want something more detailed then you are probably going to have to write your own JSON parser in PL/SQL (or Java and compile it in the database).如果您想要更详细的内容,那么您可能必须用 PL/SQL(或 Java 并在数据库中编译)编写自己的 JSON 解析器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.