Home > OS >  Oracle - how to covert xml/clob to human readable varchar
Oracle - how to covert xml/clob to human readable varchar

Time:06-08

There is a clob column binds_xml in oracle's system view v$sql_monitor. It has quasi xml format inside like below:

enter image description here

So I think how to convert such an XML to human readable format something like:

NAME POS DATATYPE VALUE
:B1 1 NUMBER 118904234
:B2 2 NUMBER 6452822

It can be stored in CLOB or VARCHAR - does not matter .

CodePudding user response:

You can use XMLTable to process the XML value, extracting the required attributes and value from each bind node:

select x.name, x.pos, x.datatype, x.value
from v$sql_monitor vsm
cross apply xmltable(
  '/binds/bind'
  passing xmltype(vsm.bind_xml)
  columns name varchar2(30) path '@name',
    pos number path '@pos',
    datatype varchar2(30) path '@dtystr',
    value varchar2(4000) path '.'
) x
order by x.pos
NAME POS DATATYPE VALUE
:B1 1 NUMBER 118904234
:B2 2 NUMBER 6452822

db<>fiddle

  • Related