1

I have to parse below json in oracle that contain array element as showing below

{"orgPhoneNum":[["9952044727"],["5464646464"]]}

I tried below statement

SELECT JSON_QUERY('{"orgPhoneNum":[["9952044727"],["5464646464"]]}', '$.orgPhoneNum') 
  FROM DUAL;

that return the result like

enter image description here

But i want to get the result like

9952044727,5464646464

What changes i will need to put in my query?

1 Answer 1

2

You can get the array values using JSON_TABLE and then aggregate using LISTAGG:

SELECT LISTAGG( orgPhoneNum, ',' ) WITHIN GROUP ( ORDER BY row_number )
         AS orgPhoneNums
FROM   JSON_TABLE(
         '{"orgPhoneNum":[["9952044727"],["5464646464"]]}',
         '$.orgPhoneNum[*][*]'
         COLUMNS (
           row_number FOR ORDINALITY,
           orgPhoneNum VARCHAR2(10) PATH '$'
         )
       )

Which outputs:

| ORGPHONENUMS          |
| :-------------------- |
| 9952044727,5464646464 |

db<>fiddle here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.