Skip to Main Content

SQL & PL/SQL

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!

How to convert quotation mark to xml

ronald_2017Dec 25 2023 — edited Dec 25 2023

Hello All,

I use Oracle 19c, I want to keep special characters when converting xml. What do you recommend?

{"name":"james", "stat_code":"3502"} => {"name":"james", "stat_code":"3502"}
with
q1 as (
  select '{"name":"james", "stat_code":"3502"}' c1, level rn from dual connect by level <= 1000
)
select xmlagg(xmlforest(rn as "id", c1 as "desc"))  from q1;

As far as I know, we can use UTL_I18N.UNESCAPE_REFERENCE. However, it doesn't accept clob data.

SQL> with
  2  q1 as (
  3    select '{"name":"james", "stat_code":"3502"}' c1, level rn from dual connect by level <= 1000
  4  )
  5  select utl_i18n.unescape_reference(xmlagg(xmlforest(rn as "id", c1 as "desc")).getClobVal())  from q1;
with
q1 as (
  select '{"name":"james", "stat_code":"3502"}' c1, level rn from dual connect by level <= 1000
)
select utl_i18n.unescape_reference(xmlagg(xmlforest(rn as "id", c1 as "desc")).getClobVal())  from q1

ORA-22835: buffer too small for clob to char or blob to raw conversion (actual: 100893, maximum: 4000)

Thanks in advance

This post has been answered by Paulzip on Jan 4 2024
Jump to Answer
Comments
Post Details
Added on Dec 25 2023
21 comments
1,264 views