Replacing contents of xml attribute in xml column in DB2

4.1k views Asked by At

I have an xml document saved in a DB2 Table with XML datatype and I want to update the value of a node. I tried this:

XQUERY replace value of node db2-fn:sqlquery('select my_xml_column from myTable where someId = someValue)/some/xpath/with/@attribute with "foobar"

(and I tried several variants, everything that google hinted that it could do the job). But unfortunatelly I am just getting error messages. Here:

SQL16002N  An XQuery expression has an unexpected token "value" following "replace ". Expected tokens may include: "

What am I doing wrong?

1

There are 1 answers

0
yankee On BEST ANSWER

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

This works and has the desired effect. It hoped for somebody to come up with a pure XQuery solution, but the problem is solved...