Skip to Main Content

Database Software

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!

Merge parent attribute to child nodes using XMLTable / XQuery.

paul zipJul 11 2013 — edited Jul 12 2013

I have the following XMLtable query, where I'm trying to transpose the parent attribute to all child rows OR return parent attribute :

select *

from XMLTable(

'for $i in /ROOT/ITEM

return element r {

   $i/../@ALL,

   $i

}'

passing XMLType(

    '<ROOT ALL="Y">

       <ITEM>1</ITEM>

       <ITEM>2</ITEM>

     </ROOT>')

columns

  "ALL" char(1) path '@ALL',

  ITEM  integer path 'ITEM'

);

| ALL | ITEM |

--------------

| Y   | 1    |

| Y   | 2    |

This works fine, but fails if I pass in the following... 

passing XMLTYPE('<ROOT ALL="Y"/>')


I want the following :


| ALL | ITEM |

--------------

| Y   |      |

I tried changing the Xpath to /ROOT/ITEM|/ROOT/[@ALL and not(ITEM)] but get syntax errors.  Am I missing something obvious?

This post has been answered by odie_63 on Jul 12 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2013
Added on Jul 11 2013
2 comments
1,880 views