简体   繁体   中英

Fetch Tag\Element value of XML from CLOB in DB2 database

i have an xml of the following structue...

Structure of XML:

<Persons>
    <PersonID>12345</Person>
    <PersonName>Larissa</Person>
    <PersonAge>28</Person>
<Persons>

<Persons>
    <PersonID>12345</Person>
    <PersonName>Larissa</Person>
    <PersonAge>28</Person>
<Persons>

The xml is in the CLOB datatype column of IBM DB2 Database.I want to fire an select query to extract the value of PersonID field and get the value 12345 in return.

Is there any functions in DB2 for xml by using which i can extract the value of the PersonID???

(Assuming DB2 Linux/Unix/Window)

You can use xquery to get the results you want:

xquery
db2-fn:xmlcolumn('YOUR_TABLE.YOUR_COLUMN')/Persons/PersonID/text()

Since this query invokes xquery directly, you have to instruct DB2 to use the xquery parser (instead of the SQL parser) by using the xquery keyword.

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