Reputation: 93
<ENVVAR CSIM:dt="list">
<item CSIM:dt="struct">
<Category dt:dt="string">ENV</Category>
<Name dt:dt="string">ABC</Name>
<Value dt:dt="string">abc</Value>
</item>
<item CSIM:dt="struct">
<Category dt:dt="string">ENV</Category>
<Name dt:dt="string">XYZ</Name>
<Value dt:dt="string">xyz</Value>
</item>
</ENVVAR CSIM>
I want to fetch the data as
Name Value
ABC abc
XYZ xyz
I am currently using
extractvalue (ABC.IOXML, '/ENVVAR/item[1]/Name') as ParaName
extractvalue (ABC.IOXML, '/ENVVAR/item[1]/Value') as ParaValue
which fetches only item[1]
values. But I want to fetch all the values in the item structure. Any help will be appreciated. Thanks.
PS: I even tried Extract
instead of extractvalue
, but it gives the data in the tags format.
Upvotes: 0
Views: 82
Reputation: 191275
You can use an XQuery, specifically here XMLTable:
select x.*
from abc
cross join xmltable (
'/ENVVAR/item'
passing xmltype(abc.ioxml)
columns name varchar2(20) path 'Name',
value varchar2(20) path 'Value'
) x;
You need to declare your CSIM namespace properly in your XML document. Demo with added xmlns:
with abc(ioxml) as (
select '<ENVVAR CSIM:dt="list" xmlns:CSIM="http://www.example.com" xmlns:dt="http://www.example.com">
<item CSIM:dt="struct">
<Category dt:dt="string">ENV</Category>
<Name dt:dt="string">ABC</Name>
<Value dt:dt="string">abc</Value>
</item>
<item CSIM:dt="struct">
<Category dt:dt="string">ENV</Category>
<Name dt:dt="string">XYZ</Name>
<Value dt:dt="string">xyz</Value>
</item>
</ENVVAR>' from dual
)
select x.*
from abc
cross join xmltable (
'/ENVVAR/item'
passing xmltype(abc.ioxml)
columns name varchar2(20) path 'Name',
value varchar2(20) path 'Value'
) x;
NAME VALUE
-------------------- --------------------
ABC abc
XYZ xyz
Upvotes: 1