我有一个xml文档保存在带有XML数据类型的DB2表中,我想更新节点的值。我试过这个:
XQUERY replace value of node db2-fn:sqlquery('select my_xml_column from myTable where someId = someValue)/some/xpath/with/@attribute with "foobar"
(我尝试了几种变体,谷歌暗示可以完成这项工作的所有内容)。 但不幸的是,我只是收到错误消息。这里:
SQL16002N An XQuery expression has an unexpected token "value" following "replace ". Expected tokens may include: "
我做错了什么?
答案 0 :(得分:1)
update myTable SET myXmlColumn = XMLQUERY('
transform copy $copy := $original
modify do replace value of $copy/some/xpath/with/@attribute with "FOOBAR"
return $copy
'
PASSING myXmlColumn AS "original"
) WHERE someId = someValue
这有效并具有预期的效果。它希望有人能够提出一个纯XQuery解决方案,但问题已经解决了......