Here is a sample table:
create table xmltemp (mydoc xmltype)
Here is a small xml doc for it:
insert into xmltemp values ( xmltype ('Canada US Washington Oregon ') )
Notice that Canada does not have a 'states' element but the US does. I'm trying to get these query results (order and formatting is not important):
Canada, US,Washington US,Oregon
When I execute this, I see both Canada and the US in the result:
select countryname from xmltemp, xmltable('/countries/country' passing mydoc columns countryname varchar2(10) path 'name')
When I do this, I get both the states:
select statename from xmltemp, xmltable('/countries/country/states/state/name' passing mydoc columns statename varchar2(20) path '.') c
I tried this to get both country and states, but it seems oracle does not like the '..' syntax:
select statename from xmltemp, xmltable('/countries/country/states/state/name' passing mydoc columns statename varchar2(20) path '.', countryname varchar2(20) path '../../../name') c
Heres the error:
ORA-19110: unsupported XQuery expression
When I try this, I get the 'multi-item' error because of the two states:
select countryname, statename from xmltemp, xmltable('/countries/country' passing mydoc columns countryname varchar2(10) path 'name', statename varchar2(20) path 'states/state/name') c
Here is that error:
ORA-19279: XPTY0004 - XQuery dynamic type mismatch: expected singleton sequence - got multi-item sequence
What's a query that will get me my desired output of:
Canada, US,Washington US,Oregon
Thanks