db2 xml 转 table【XQuery系列】

前端之家收集整理的这篇文章主要介绍了db2 xml 转 table【XQuery系列】前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

版本:DB2 Version 9.1

1.创建测试表,初始化数据

create table emp (doc XML);
@H_301_20@
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.利用xmltable方法,将xml格式数据转换为临时table

SELECTX.* @H_301_20@ FROMemp,
XMLTABLE ( '$d/dept/employee' passing doc as "d"
COLUMNS
empID INTEGER PATH '@id' ,
firstname VARCHAR (20) PATH 'name/first' sql plain" style="white-space:pre-wrap; margin:0px!important; padding:0px!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.8em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
lastname (25) PATH 'name/last' ) AS X

结果图:

猜你在找的XML相关文章