【发布时间】:2020-11-16 06:18:17
【问题描述】:
我正在使用 Oracle 19c 和 JSON_ARRAYAGG 函数(使用 JSON_OBJECT)返回 JSON 对象的串联数组字符串。我需要根据 ORDER BY SENT_DATE DESC 将结果限制为前 10 个对象。
注意JSON_ARRAYAGG 有自己的ORDER BY,所以我把它放在那里。但是,有限制设施吗?
以下语法正确,但结果不正确。我的 JSON 对象在串联字符串中不是 SENT_DATE DESC 顺序。
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)
ORDER BY mh.sent_date DESC) /*ORDER BY inside json_arrayagg)*/
/*Normally this works, but not with ROWNUM*/
from mail_history_t mh
where mh.plan_id = 763 and mh.is_current_status = 'Y' and rownum <= 10; /*ROWNUM outside*/
如果我在通常的行查询中检查顶部结果,我发现这是不正确的,
select * from mail_history_t where plan_id = 763 and is_current_status ='Y' order by sent_date desc;
【问题讨论】:
标签: sql arrays json oracle oracle19c