Skip to Main Content

Data Lake & Services

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSON_OBJECTAGG and ORDER BY

soutouNov 15 2021

Hi,
COL employes FORMAT A80
WITH cte AS (SELECT employee_id,first_name,last_name,hire_date
FROM employees WHERE employee_id BETWEEN 100 AND 120
ORDER BY last_name)
SELECT JSON_OBJECTAGG(KEY 'employes' VALUE
JSON_OBJECT(KEY 'id' VALUE employee_id,
KEY 'prenom' VALUE first_name,
KEY 'nom' VALUE last_name,
KEY 'embauche' VALUE TO_CHAR(hire_date,'YYYY-MM-DD')))
AS employes
FROM cte;
returns a correct JSON but not ordered.
Replacing by the name of columns of the CTE the result is ordered.
I don't know why?
Best regards

This post has been answered by Solomon Yakobson on Nov 16 2021
Jump to Answer

Comments

Post Details

Added on Nov 15 2021
5 comments
939 views