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?