gen*_* b. 4 sql oracle oracle19c
使用 Oracle 19c:
我有以下查询,其中子选择(通过 链接到主选择plans1_.ID)使用该JSON_ARRAYAGG函数。
select
... , /* Other columns... */
(SELECT
json_arrayagg(json_object('sentDate' value mh.sent_date,
'sentByEmail' value mh.send_by_email,
'sentBy' value mh.sent_by,
'sentByName' value mh.sent_by_name,
'sentToEmail' value mh.sendee_email) RETURNING CLOB)
from mail_history_t mh
where mh.plan_id = plans1_.id and mh.is_current_status = 'Y'
/*---This is the problem block: If I remove this ORDER BY the query works---*/
order by mh.sent_date desc
) as col_33_0_,
/* ... */
from TABLE_T table0_
left outer join PLANS_T plans1_
on table0_.SOME_ID=plans1_.SOME_ID
where ... /* etc. */
Run Code Online (Sandbox Code Playgroud)
当我有order by作为我的一部分时select from mail_history_t mh,我收到错误
00907. 00000 - "missing right parenthesis"
Run Code Online (Sandbox Code Playgroud)
但是当我去掉order by子句时,查询就起作用了。此外,如果我要隔离它,则子选择会自行工作。
我的目标是获取具有满足条件但按sent_dateDESC排序的列的行的 JSON-Array 表示。
JSON_ARRAYAGG()接受自己的ORDER BY条款:
json_arrayagg(json_object('sentDate' value mh.sent_date,
'sentByEmail' value mh.send_by_email,
'sentBy' value mh.sent_by,
'sentByName' value mh.sent_by_name,
'sentToEmail' value mh.sendee_email
) ORDER BY mh.sent_date desc RETURNING CLOB
)
Run Code Online (Sandbox Code Playgroud)
ORDER BY 不推荐在子查询中。