在带有 ORDER BY 的 Sub-Select 中使用 JSON_ARRAYAGG 给出错误
Using JSON_ARRAYAGG in a Sub-Select with ORDER BY gives error
使用 Oracle 19c:
我有以下查询,其中 Sub-Select(通过 plans1_.ID
链接到主 Select)使用 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
子句时,查询有效。此外,如果我要隔离它,Sub-Select 会自行工作。
我的目标是获取具有满足条件的列的行的 JSON-数组表示,但按 sent_date
DESC 排序。
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
)
不建议在子查询中使用 ORDER BY
。
使用 Oracle 19c:
我有以下查询,其中 Sub-Select(通过 plans1_.ID
链接到主 Select)使用 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
子句时,查询有效。此外,如果我要隔离它,Sub-Select 会自行工作。
我的目标是获取具有满足条件的列的行的 JSON-数组表示,但按 sent_date
DESC 排序。
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
)
不建议在子查询中使用 ORDER BY
。