简体   繁体   中英

convert XML to table in oracle

I have a XML in the below format, store in column of XMLType in oracle database

<a>
<c>1</c>
<c>2</c>
</a>

I need to convert this in table format as

c
1
2

Any idea how to do this using SQL?

with data as
(select '<a><c>1</c><c>2</c></a>' xmlval
 from dual)
( select c
  from data d, 
       xmltable('/a/*' passing xmltype(d.xmlval) 
        columns
    c varchar2(254) path '/c'   
))  

There is answer in this url .

For instance user daggett did this:

select *  
FROM XMLTABLE('/person/row'  
         PASSING   
            xmltype('
                <person>
                   <row>
                       <name>Tom</name>
                       <Address>
                           <State>California</State>
                           <City>Los angeles</City>
                       </Address>
                   </row>
                   <row>
                       <name>Jim</name>
                       <Address>
                           <State>California</State>
                           <City>Los angeles</City>
                       </Address>
                   </row>
                </person>
            ')
         COLUMNS  
            --describe columns and path to them:  
            name  varchar2(20)    PATH './name',  
            state varchar2(20)    PATH './Address/State',  
            city  varchar2(20)    PATH './Address/City'
     ) xmlt  
;  

Thanks, it's work.

pISLEMLER CLOB;

    select *  
    FROM XMLTABLE('/mydata/UCRET'  
             PASSING   
                xmltype('<mydata>'||pISLEMLER||'</mydata>
                ')
             COLUMNS  
                --describe columns and path to them:  
                F_M_IS_ID  varchar2(20)    PATH './FMISID',  
                ISKONTO varchar2(20)    PATH 'ISK'
         ) xmlt;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM