Im having trouble trying to retrieve data from a JSON that is stored in a CLOB column.
The part im trying to retrive is:
"multiplaResposta":["Cardiologista","Endocrinologista","Neurologista","Pneumologista"]
The closed I managed is this:
SELECT jt.*
FROM FICHAS_AVALIACAO_HEALTHCHESS fa
CROSS APPLY JSON_TABLE(
fa.json_data,
'$[*].respostas[*]'
COLUMNS (
pergunta VARCHAR2(200) PATH '$.pergunta',
resposta VARCHAR2(4000) PATH '$.resposta',
multiplaResposta1 CLOB FORMAT JSON PATH '$.multiplaResposta',
multiplaResposta2 CLOB PATH '$.multiplaResposta'
)
) jt
OUTER APPLY JSON_TABLE(
COALESCE(jt.multiplaResposta1, '["' || jt.multiplaResposta2 || '"]'),
'$[*]'
COLUMNS(
multiplaResposta CLOB PATH '$'
)
) m
WHERE fa.cpf = '213.029.030-20';
But that only gives me another column indicating that the output is a CLOB information. What i need is something like this on the output:
multiplaResposta |
---|
Cardiologista, Endocrinologista, Neurologista, Pneumologista |
2
Answers
The solution I got, the same code I post on the question, but using LISTAGG and DBMS_LOB.SUBSTR, here:
LISTAGG(DBMS_LOB.SUBSTR(m.multiplaResposta, 4000, 1), ' | ') WITHIN GROUP (ORDER BY MULTIPLARESPOSTA) AS multiplaResposta
Thanks everyone!
If your clob column containes json data like here:
… then …
fiddle