【发布时间】:2020-11-06 14:07:33
【问题描述】:
使用 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. */
当我将order by 作为我的select from mail_history_t mh 的一部分时,我得到了错误
00907. 00000 - "missing right parenthesis"
但是当我去掉order by 子句时,查询就起作用了。此外,如果我要隔离它,子选择会自行工作。
我的目标是获取列满足条件但按sent_date DESC 排序的行的 JSON 数组表示。
【问题讨论】:
-
不要在子查询中排序。这是不允许的。