use*_*527 1 sql oracle updatexml xmltype oracle11g
我在Oracle 11g的CLOB列中有这个xml值:
<Energy xmlns="http://euroconsumers.org/notifications/2009/01/notification">
<Gender>M</Gender>
<FirstName>MAR</FirstName>
<Name>VAN HALL</Name>
<Email/><Telephone>000000000</Telephone>
<InsertDate>2013-10-09</InsertDate>
</Energy>
Run Code Online (Sandbox Code Playgroud)
我想为几行更新InserDate的值.
我正在使用下面的sql命令:
update tmp_tab_noemail_test p1
set p1.sce_msg = updatexml(xmltype(p1.sce_msg),
'//Energy/InsertDate/text()','Not Valid').getClobVal()
Run Code Online (Sandbox Code Playgroud)
但是没有用.
您是否有一些想法只修改InsertDate的xml标记的值?
谢谢你的进步
您的顶级Energy节点中有一个命名空间,因此您没有匹配; UPDATEXML文档显示您可以选择提供命名空间字符串.
所以你可以使用你的示例数据来做到这一点:
create table tmp_tab_noemail_test (sce_msg clob);
insert into tmp_tab_noemail_test values (
'<Energy xmlns="http://euroconsumers.org/notifications/2009/01/notification">
<Gender>M</Gender>
<FirstName>MAR</FirstName>
<Name>VAN HALL</Name>
<Email/><Telephone>000000000</Telephone>
<InsertDate>2013-10-09</InsertDate>
</Energy>');
update tmp_tab_noemail_test p1
set p1.sce_msg = updatexml(xmltype(p1.sce_msg),
'/Energy/InsertDate/text()','Not Valid',
'xmlns="http://euroconsumers.org/notifications/2009/01/notification"').getClobVal();
Run Code Online (Sandbox Code Playgroud)
之后你最终得到:
select sce_msg from tmp_tab_noemail_test;
SCE_MSG
--------------------------------------------------------------------------------
<Energy xmlns="http://euroconsumers.org/notifications/2009/01/notification"><Gender>M</Gender><FirstName>MAR</FirstName><Name>VAN HALL</Name><Email/><Telephone>000000000</Telephone><InsertDate>Not Valid</InsertDate></Energy>
Run Code Online (Sandbox Code Playgroud)
或者滚动略少:
select XMLQuery('//*:InsertDate' passing XMLType(sce_msg) returning content) as insertdate
from tmp_tab_noemail_test;
INSERTDATE
--------------------------------------------------------------------------------
<InsertDate xmlns="http://euroconsumers.org/notifications/2009/01/notification">Not Valid</InsertDate>
Run Code Online (Sandbox Code Playgroud)
您还可以使用通配符更新:
update tmp_tab_noemail_test p1
set p1.sce_msg = updatexml(xmltype(p1.sce_msg),
'/*:Energy/*:InsertDate/text()','Not Valid').getClobVal();
Run Code Online (Sandbox Code Playgroud)
...但是指定命名空间可能更好.