|
|
|
|
|
|
Re: How to get the Single Tag out of XML [message #516812 is a reply to message #516052] |
Thu, 21 July 2011 01:14 |
|
rajavu1
Messages: 1574 Registered: May 2005 Location: Bangalore , India
|
Senior Member |
|
|
Elegantly excellent Barbara.. You are rocking .. Btw, I was using the following query. You suggestion is much better than the current one
11:41:35 SQL> with rec AS (
select XMLTYPE(
11:41:36 2 11:41:36 3 '<connection value="0">
11:41:36 4 <GroupDetails>
11:41:36 5 <info groupId="100" classType="0"/>
11:41:36 6 <info groupId="128" classType="1"/>
11:41:36 7 <info groupId="179" classType="0"/>
11:41:36 8 <info groupId="198" classType="0"/>
11:41:36 9 </GroupDetails>
11:41:36 10 </connection>') x
11:41:36 11 from dual)
11:41:36 12 select INSERTXMLBEFORE(DELETEXML(x,'connection/GroupDetails/info[@classType="1"]'),
11:41:36 13 'connection/GroupDetails/info[1]',value(y))
11:41:36 14 from rec ,
11:41:36 15 table(xmlsequence(extract(x, '/connection/GroupDetails/info'))) y
11:41:36 16 where extractvalue(value(y), '//info/@classType') = 1 ;
INSERTXMLBEFORE(DELETEXML(X,'CONNECTION/GROUPDETAILS/INFO[@CLASSTYPE="1"]'),'CON
--------------------------------------------------------------------------------
<connection value="0">
<GroupDetails>
<info groupId="128" classType="1"/>
<info groupId="100" classType="0"/>
<info groupId="179" classType="0"/>
<info groupId="198" classType="0"/>
</GroupDetails>
</connection>
11:41:37 SQL>
|
|
|
Re: How to get the Single Tag out of XML [message #516856 is a reply to message #516812] |
Thu, 21 July 2011 03:37 |
_jum
Messages: 577 Registered: February 2008
|
Senior Member |
|
|
This can be simplified to:
WITH rec AS
(SELECT xmltype ('<connection value="0">
<GroupDetails>
<info groupId="100" classType="0"/>
<info groupId="128" classType="1"/>
<info groupId="179" classType="0"/>
<info groupId="198" classType="0"/>
</GroupDetails>
</connection>') x FROM DUAL)
SELECT
INSERTXMLBEFORE(DELETEXML(x,'connection/GroupDetails/info[@classType="1"]'),
'connection/GroupDetails/info[1]', EXTRACT (x,'//info[@classType=1]')) nx
FROM rec;
NX
--------------------------------------------
<connection value="0">
<GroupDetails>
<info groupId="128" classType="1"/>
<info groupId="100" classType="0"/>
<info groupId="179" classType="0"/>
<info groupId="198" classType="0"/>
</GroupDetails>
</connection>
|
|
|
|
|
|