XMLtable with Oracle 11g

前端 未结 1 2039
鱼传尺愫
鱼传尺愫 2021-01-01 03:07

Here is a sample table:

create table xmltemp (mydoc xmltype)

Here is a small xml doc for it:

insert into xmltemp values (
x         


        
相关标签:
1条回答
  • 2021-01-01 04:02

    Try this:

    select      X.COUNTRYNAME, Y.STATENAME
    from        XMLTEMP
               ,xmltable('/countries/country'
                         passing MYDOC
                         columns COUNTRYNAME varchar2(20) path './name', 
                                 STATES xmltype path './states') X,
                xmltable('/states/state/name' passing X.STATES 
                        columns STATENAME varchar2(20) path '.') (+) Y
    

    Because you have multiple states you should join to another xml table. As some countries have no states then it needs to be a left outer join. I'm using the old method of (+) as I'm trying this on 10g and it seems there's a problem using left outer join in 10g but apparently it should be fine in 11g.

    0 讨论(0)
提交回复
热议问题