开发者

Xquery to update value of a node of a xml stored in a column of a table

i use DB2 express-c edition v9.1 database management system.

name of the table: student

name of the column: course

xml in the column:

<ids>
<course>
<id>

**101**  

</id> 
<lecture-id>

**0**  
</lecture-id>

</course>
<course>
<id>

**102**  

</id>
<lecture-id>

**2**  

</lecture-id>
</course>
</ids>
开发者_JAVA百科

I need to update the value of <lecture-id> node of <course> node with <id> node as 101, to 1.

how should I query the database to get the desired result.

any help would be highly appreciated.


I think it can be like this:

    UPDATE student
       SET course = XMLQUERY('transform 
                            copy      $new := $i
                            modify    do replace value of $new/ids/course/lecture-id
                                                       with 1
                            return    $new' PASSING course AS "i")

 WHERE id = 101;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜