简体   繁体   中英

How to parse XML in PL/SQL

I have following xml struct in pl/sql:

<struct>
  <member>
    <name>CODE</name>
    <value>
      <integer>0</integer>
    </value>
  </member>
  <member>
    <name>MSG</name>
    <value>
      <string>Some message</string>
    </value>
  </member>
</struct>

How can i extract values in path /member/value/some_type using text in name tag? I mean something like this:

extract('//member/value/*[filter name tag = CODE]').getStringValue

You can achieve this using local-name()

XPath should be,

//member/value/*[local-name()='CODE']

Example:

  1. //member/value/*[local-name()='integer']
  2. //member/value/*[local-name()='string']

Result:

  1. 0
  2. Some message

UPDATE:

In this case, you XPath should be

//member[*='CODE']/*/*
//member[*='MSG']/*/*

Result:

  1. 0
  2. Some message

The short answer is you don't treat databases as ETL (extract,transform,load) tools. What you want to do is pass this XML file to a separate program that uses XPath and process it that way. Databases are only supposed to store data. In fact I have spent the past 5 months removing "exotic " code like this that made an Oracle database take 72+ hours to insert 400k rows. So again offset this to xpath

The query will look almost identical to your command above

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