db2 xml 转 table【XQuery系列】
版本:DB2 Version 9.11.创建测试表,初始化数据
createtableemp(doc XML);
INSERTINTOEMPVALUES('<deptbldg="101">
<employeeid="901">
<name>
<first>John</first>
<last>Doe</last>
</name>
<office>344</office>
<salarycurrency="USD">55000</salary>
</employee>
<employeeid="902">
<name>
<first>Peter</first>
<last>Pan</last>
</name>
<office>216</office>
<phone>905-416-5004</phone>
</employee>
</dept>');
2.利用xmltable方法,将xml格式数据转换为临时table
SELECTX.*
FROMemp,
XMLTABLE('$d/dept/employee'passingdoc as"d"
COLUMNS
empIDINTEGERPATH'@id',
firstnameVARCHAR(20)PATH 'name/first',
lastnameVARCHAR(25)PATH 'name/last')ASX
结果图:
http://images.cnitblog.com/blog/539815/201306/26102624-3849e248d9984108bdd7c674e361bdc2.png
页:
[1]