Db2 xml to table

Source: Internet
Author: User

Db2 xml to table Version: DB2 Version 9.1 1. Create a test table and initialize data

create table emp (doc XML);INSERT INTO EMP VALUES ('<dept bldg="101">    <employee id="901">        <name>            <first>John</first>            <last>Doe</last>        </name>        <office>344</office>        <salary currency="USD">55000</salary>    </employee>    <employee id="902">        <name>            <first>Peter</first>            <last>Pan</last>        </name>        <office>216</office>        <phone>905-416-5004</phone>    </employee></dept>');

 

2. Use the xmltable method to convert xml format data to a temporary table
?SELECT X.* FROM emp, XMLTABLE ('$d/dept/employee' passing doc as "d"   COLUMNS    empID    INTEGER     PATH '@id',   firstname    VARCHAR(20)     PATH 'name/first',   lastname     VARCHAR(25)     PATH 'name/last') AS X

 

Result chart:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.