简体   繁体   中英

Parse Multiple Json Array Elements in Oracle

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

在此处输入图像描述

But i want to get the result like

9952044727,5464646464

What changes i will need to put in my query?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM