oracle to deal the xml field

For more information ,you can move to the website:

 

http://www.adp-gmbh.ch/xml/xpath.html

 

 

如果xml字段中有多个相同的item,比如object节点下面有多个void,则用[ ]中括号来指定哪一个void 。

 

 

select * from

extractvalue(xmltype(new_value), '//object/void[1]/object/void[attribute::property=''type'']/string') "eventType",

 

extractvalue(xmltype(new_value), '//object/void[2]/object/void[attribute::property=''type'']/string') "eventType"

 

from my_xml.

 

createtable my_xml

(

OLD_VALUE CLOB,

NEW_VALUE CLOB

)

insertinto my_xml(old_value,new_value)values('<product_details id="1">

<product id="21">

<name>test1</name>

<code>123</code>

</product>

<product id="20">

<name>test2</name>

<code>456</code>

</product>

</product_details>

','<product_details id="1">

<product id="21">

<name>test1</name>

<code>123</code>

</product>

<product id="20">

<name>test2</name>

<code>456</code>

</product>

</product_details>

');

select *from my_xml;

/*

<product_details id="1">

<product id="21">

<name>test1</name>

<code>123</code>

</product>

<product id="20">

<name>test2</name>

<code>456</code>

</product>

</product_details>*/

 

selectextractvalue(xmltype(new_value),'//product[attribute::id=''21'']/name') "name"from my_xml mx;

 

selectextractvalue(xmltype(new_value),'//product[attribute::id=''21'']/code') "code"from my_xml mx;

 

 

Tip:

1,because the type of mx.new_value in table my_xml is 'clob'*(see the sql of  create table ),so the first step ,you should change the type fromclob toxmltype by using xmltype funtion ,so that oracle can understand how to deal it.

 

2,you must set the path of xml field for extractvaluefunction as its second parameter ,

for the path ,you must attendtion,you can't return more than one value for the path ,in other words,you shoud using just like above[@id=1]to make sure return one value only.

 

 For more information ,you can move to the website:

 

http://www.adp-gmbh.ch/xml/xpath.html

 

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值