我想看看是否有可能在Oracle中将JSON格式化为头列表,然后列出所有值集。
创建以下内容(在Oracle 19 c上):
CREATE TABLE tbl1 (val1 varchar2(10), val2 varchar2(10), val3 varchar2(10));
INSERT INTO tbl1 VALUES ('1','2','3');
INSERT INTO tbl1 VALUES ('a','b','c');
INSERT INTO tbl1 VALUES ('1','b','3');
字符串
运行此查询可得到:
SELECT JSON_ARRAYAGG(JSON_OBJECT (*) returning varchar2) AS JSON_VAR
FROM tbl1;
型
| JSON_VAR |
| ------------ |
| [{"VAL1":"1","VAL2":"2","VAL3":"3"},{"VAL1":"a","VAL2":"b","VAL3":"c"},{"VAL1":"1","VAL2":"b","VAL3":"3"}] |
是否可以格式化输出,其中我们列出一次键,然后列出所有的值集?举例来说:
{"keys" : ["VAL1", "VAL2", "VAL3"], "values" : [["1", "2", "3"],["a", "b", "c"],["1","b","c"]]}
1条答案
按热度按时间fykwrbwg1#
字符串