Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Sheriff.

Asked: October 29, 2015 - 3:03 am UTC

Last updated: October 29, 2015 - 10:18 am UTC

Version: 11.2.3

Viewed 1000+ times

You Asked

Im trying to parse xml statement for example :

"<root><AddrLn1>UNITED STATES MARSHALS OFFICE</AddrLn1><AddrLn2>MLK JR FEDERAL COURTHOUSE</AddrLn2></root>"

So I am trying to create a table and bein able to create columns and then parse the data.

I want to take the above data and insert it individually in a column on a database table. Is it possible to just make a fairly simple version of what the SQL statement code will look like?

For example >>>

Addrln1 = column in the table
inserted data = UNITED STATES MARSHALS OFFICE

From there vice versa next column would be Addrln2 = columns
Inserted data = MLK JR FEDERAL COURTHOUSE

and Chris said...

You can use xmltable to extract the fields. Use XPath expressions to identify columns:

select * 
from   xmltable('/root'
  passing 
  xmlparse(content '<root>
     <AddrLn1>UNITED STATES MARSHALS OFFICE</AddrLn1>
     <AddrLn2>MLK JR FEDERAL COURTHOUSE</AddrLn2>
  </root>')
  columns line_1 varchar2(100) path 'AddrLn1',
          line_2 varchar2(100) path 'AddrLn2');

LINE_1                         LINE_2                       
------------------------------ ------------------------------
UNITED STATES MARSHALS OFFICE  MLK JR FEDERAL COURTHOUSE 


http://docs.oracle.com/database/121/ADXDB/xdb03usg.htm#ADXDB4130

https://oracle-base.com/articles/misc/xmltable-query-xml-data-from-sql


Is this answer out of date? If it is, please let us know via a Comment