Update xml tag in a CLOB column in Oracle(更新 Oracle 中 CLOB 列中的 xml 标记)
问题描述
我在 Oracle 11g 的 CLOB 列中有这个 xml 值:
I have this xml value in a CLOB column in Oracle 11g:
<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>
我想更新几行的 InserDate 值.
I want to update the value of InserDate for several rows.
我正在使用下面的 sql 命令:
I was using next below sql command:
update tmp_tab_noemail_test p1
set p1.sce_msg = updatexml(xmltype(p1.sce_msg),
'//Energy/InsertDate/text()','Not Valid').getClobVal()
但是不起作用.
你有什么想法只修改InsertDate的xml标签的值吗?
Do you have some ideas to modify only the values of the xml tag of InsertDate?
提前感谢
推荐答案
您的顶级 Energy 节点中有一个命名空间,因此您无法匹配;UPDATEXML 文档 显示您可以选择提供命名空间字符串.
You have a namespace in your top-level Energy node, so you aren't matching without; the UPDATEXML documentation shows you can optionally supply a namespace string.
因此您可以使用示例数据执行此操作:
So you can do this, using your example data:
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();
之后你会得到:
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>
或者稍微减少滚动:
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>
<小时>
您也可以通配更新:
You could also wildcard the update:
update tmp_tab_noemail_test p1
set p1.sce_msg = updatexml(xmltype(p1.sce_msg),
'/*:Energy/*:InsertDate/text()','Not Valid').getClobVal();
...但最好指定命名空间.
... but it's probably better to specify the namespace.
这篇关于更新 Oracle 中 CLOB 列中的 xml 标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更新 Oracle 中 CLOB 列中的 xml 标记
基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
