Oracle:如何使用updateXML 更新文档中的多个节点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/405679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 17:37:55  来源:igfitidea点击:

Oracle: how to use updateXML to update multiple nodes in a document?

xmloracleupdatexml

提问by avernet

I can write:

我可以写:

update my_table
set xml = updateXML(xml, '/a/b', '1')
where document_id = 123

Now what if in the same update query I also want to set /a/c to 2 (in addition /a/b to 1)? I am tempted to write:

现在,如果在同一个更新查询中我还想将 /a/c 设置为 2(另外将 /a/b 设置为 1)呢?我很想写:

update my_table
set 
    xml = updateXML(xml, '/a/b', '1'),
    xml = updateXML(xml, '/a/c', '2')
where document_id = 123

But this give me a "ORA-00957: duplicate column name". Any suggestion on how to do this?

但这给了我一个“ORA-00957:重复的列名”。关于如何做到这一点的任何建议?

回答by Gary Myers

The documentation indicates that the XPath string and expression can be repeated http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions205.htm#i1134878

文档表明 XPath 字符串和表达式可以重复 http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions205.htm#i1134878

so try

所以试试

update my_table set xml = updateXML(xml, '/a/b', '1', '/a/c', '2') where document_id = 123

更新 my_table set xml = updateXML(xml, '/a/b', '1', '/a/c', '2') where document_id = 123

回答by veeraswamy valluru

update my_table set
xml = updateXML(xml, '/a/b/text()', '1','/a/c/text()','2') where document_id = 123

更新 my_table set
xml = updateXML(xml, '/a/b/text()', '1','/a/c/text()','2') where document_id = 123