示例查询
下面是示例查询:
替换节点:action=replace。
通过使用复杂名称元素替换简单名称元素来更新测试文档:
Call DB2XMLFUNCTIONS.XMLUPDATE ('<updates namespaces="x:http://posample.org"><update action="replace" col="1" path="/x:customerinfo/x:name"><name><fname>Hardeep</fname><lname>Singh</lname></name></update></updates>','Select info from XMLCustomer where cid=1006','update XMLCustomer set info=? where cid=1006',?,?);
使用 SQL 查询获取新值以进行更新:
using=SQL。Call DB2XMLFUNCTIONS.XMLUPDATE ('<updates namespaces="x:http://posample.org"><update using="sql" action="replace" col="1"path="//x:customerinfo[@Cid=1006]/x:addr/x:pcode-zip/text()">select cid from XMLCustomer where cid=1006</update></updates>','Select info from XMLCustomer where cid=1006','update XMLCustomer set info=? where cid=1006',?,?);
使用给定表达式来计算值:
action=compute。Call DB2XMLFUNCTIONS.XMLUPDATE ('<updates namespaces="x:http://posample.org"><update action="compute" col="1"path="/x:customerinfo/x:addr/x:pcode-zip/text()">(20+?)*32-?</update></updates>','Select info from XMLCustomer where cid=1006','update XMLCustomer set info=? ÿhere cid=1006',?,?);
对目标 XML 文档执行多个操作:
Call DB2XMLFUNCTIONS.XMLUPDATE ('<updates namespaces="x:http://posample.org"><update using="sql" action="replace" col="1"path="/x:customerinfo/x:addr/x:pcode-zip/text()">select cid from XMLCustomer where cid=1006</update><update action="compute" col="1"path="/x:customerinfo/x:addr/x:pcode-zip/text()">(2+?)*10-?</update><update action="delete" col="1" path="/x:customerinfo/x:name"/></updates>','Select info from XMLCustomer where cid=1006','update XMLCustomer set info=? where cid=1006',?,?);
更新文档时对其进行验证。
为此,您需要创建模式并在 XSR 中注册。
Call DB2XMLFUNCTIONS.XMLUPDATE ('<updates namespaces="x:http://posample.org"><update using="sql" action="replace" col="1"path="/x:customerinfo/x:addr/x:pcode-zip/text()">select cid from XMLCustomer where cid=1006</update></updates>','Select info from XMLCustomer where cid=1006','update XMLCustomer set info=xmlvalidate(? according to XMLSCHEMA ID test.schema2) where cid=1006',?,?)
使用 XMLUpdate 替换属性值。
Call DB2XMLFUNCTIONS.XMLUPDATE ('<updates namespaces="x:http://posample.org"><update action="replace" col="1"path="/x:customerinfo/x:phone/@type">tie line</update></updates>','Select info from XMLCustomer where cid=1006','update XMLCustomer set info=? where cid=1006',?,?);
使用 XMLUpdate 替换文本值。
Call DB2XMLFUNCTIONS.XMLUPDATE ('<updates namespaces="x:http://posample.org"><update action="replace" col="1"path="/x:customerinfo/x:addr/x:city/text()">San Jose</update></updates>','Select info from XMLCustomer where cid=1006','update XMLCustomer set info=? where cid=1006',?,?);
(编辑:aniston)
·2024年12月目录 ·2024年11月目录 ·2024年10月目录 ·2024年9月目录 ·2024年8月目录 ·2024年7月目录 ·2024年6月目录 ·2024年5月目录 ·2024年4月目录 ·2024年3月目录 ·2024年2月目录 ·2024年1月目录 ·2023年12月目录 ·2023年11月目录