我需要创建一个数组下具有两组JSON对象的JSON。这些对象包含来自多个表的聚合数据。当我使用json_arrayagg时,出现此错误:
ORA-02000:缺少)关键字
代码应有助于解释我已经做过的事和需要的事。
SELECT JSON_OBJECT(
'rData' VALUE JSON_ARRAYAGG(
JSON_OBJECT(
'datapoints' VALUE JSON_ARRAY(JSON_OBJECT('key' VALUE 'ENM008137Q00190',
'value' VALUE tab3.column_6)),
'datatype' VALUE 'DATA_TYPE',
'id' VALUE tab1.column_4,
'key' VALUE tab3.column_1,
'timestamp' VALUE tab1.column_7),
JSON_OBJECT(
'id' VALUE tab1.column_4,
'key' VALUE tab3.column_1,
'timestamp' VALUE tab1.column_7,
'datatype' VALUE 'DATA_TYPE_2',
'datapoints' VALUE JSON_ARRAYAGG(JSON_OBJECT(
'key' VALUE tab5.column_8,
'value' VALUE tab2.column_9))))RETURNING CLOB)
FROM table_3 tab3,
table_4 tab4,
table_2 tab2,
table_1 tab1,
table_5 tab5
WHERE tab1.column_1 = tab2.column_1
AND tab3.column_2 = tab4.column_2
AND tab3.column_1 = tab2.column_1
AND tab1.column_1 = tab3.column_1
AND tab2.column_3 = tab5.column_3
AND tab2.latenttypeid = 1
AND tab3.column_2 = 2952326910
AND tab2.column_10 = 8878887
AND tab3.column_10 = 8878887
AND tab1.date BETWEEN '19-jun-19'
AND '25-jun-19'
GROUP BY tab1.column_4, tab3.column_1, tab3.column_6, tab1.column_7;
这是我想要的json输出:
{
"rData": [{
"datapoints": [
{"key" : "ENM008137Q00190","value" : "10"}
],
"datatype": "DATA_TYPE",
"id": "H2hnJikUKAhGVzslBVBHqg86DnwGhh8V",
"key": "534421188",
"timestamp": "2019-07-05T05:33:12.000Z"
},
{
"key":"534421188",
"id":"H2hnJikUKAhGVzslBVBHqg86DnwGhh8V" ,
"timestamp": "2019-07-05T05:33:12.000Z",
"datatype": "DATA_TYPE_2",
"datapoints": [
{"key" : "ENM008137L0001","value" : "56.0869029"},
{"key" : "ENM008137L0002","value" : "59.79244788"},
{"key" : "ENM008137L0003","value" : "73.34481183"},
{"key" : "ENM008137L0004","value" : "43.94661396"},
{"key" : "ENM008137L0005","value" : "80.71909567"},
{"key" : "ENM008137L0006","value" : "97.2707082"}
]
},{
"datapoints": [
{"key" : "ENM008137Q00190","value" : "9"}
],
"datatype": "DATA_TYPE",
"id": "A1JnnNjUKAhGVzslBVBHqg86Dnw52Ccj",
"key": "534421164",
"timestamp": "2019-07-05T04:27:45.000Z"
},
{
"key":"534421164",
"id":"A1JnnNjUKAhGVzslBVBHqg86Dnw52Ccj" ,
"timestamp": "2019-07-05T04:27:45.000Z",
"datatype": "DATA_TYPE_2",
"datapoints": [
{"key" : "ENM008137L0001","value" : "88.0869029"},
{"key" : "ENM008137L0002","value" : "88.79244788"},
{"key" : "ENM008137L0003","value" : "88.34481183"},
{"key" : "ENM008137L0004","value" : "82.94661396"},
{"key" : "ENM008137L0005","value" : "99.71909567"},
{"key" : "ENM008137L0006","value" : "88.2707082"}
]
}]
}
“ rData”数组下有2个json_objects,这是我想要聚合的两个数据源,但是我不确定当前函数是否可以实现。
我对代码表示歉意,我已尝试为您提供最少的信息来帮助您。当然,任何帮助总是值得赞赏的。