我正在尝试更新oracle中的xml列,并得到我无法解决的错误。在这里需要一些帮助
如果数据在那里,并且其“美国”仅更新值或不执行任何操作
update USER.TABLE t1
set t1.xmlrecord=
XMLQuery('
copy $t := . modify (
if(fn:exists(/row/c2)) then replace value of node $t/row/c2 with concat("firstname",$t/row/@id) else(),
if(fn:exists(/row/c3)) then replace value of node $t/row/c3 with concat("lastname",$t/row/@id) else(),
if (fn:exists(/row/c178[@m=83])) and $t/row/c178[@m=82]="USA" then replace value of node $t/row/c178[@m=83] with ("NEW YORK") else(),
if(fn:exists(/row/c4)) and $t/row/c178[@m=82]="USA" then replace value of node $t/row/c4 with ("Manhattan") else(),
if(fn:exists(/row/c5)) and $t/row/c178[@m=82]="USA" then replace value of node $t/row/c5 with concat(" NY 10036, USA.",$t/row/@id) else()
)
return $t
'
passing t1.xmlrecord
returning content
);
ORA-19114: XPST0003 - error during parsing the XQuery expression:
LPX-00801: XQuery syntax error at 'and'
5 if
(fn:exists(/row/c178[@m=83])) and $t/row/c178[@m=82]="USA" then replace
- ^
ORA-06512: at line 6
我没有正确满足这两个条件 (fn:exists(/ row / c178 [@ m = 83]))和$ t / row / c178 [@ m = 82] =“美国”
这单个条件工作正常->(fn:exists(/ row / c178 [@ m = 83]))就像我在其他表中使用它一样,但是当我们添加第二个条件时,一切都搞砸了- > $ t / row / c178 [@ m = 82] =“美国”
答案 0 :(得分:0)
更新USER.TABLE t1
设置t1.xmlrecord =
XMLQuery('
复制$ t:=。修改(
如果fn:exists / row / c2存在,则将节点$ t / row / c2的值替换为concat(“ firstname”,$ t / row / @ id)else(),
如果fn:exists / row / c3存在,则将节点$ t / row / c3的值替换为concat(“ lastname”,$ t / row / @ id)else(),
如果 ((fn:exists(/ row / c178 [@ m = 83]))和($ t / row / c178 [@ m = 82] =“ USA”)) ,然后将节点$ t / row / c178 [@ m = 83]的值替换为(“ NEY YORK”)else(),
如果((fn:exists(/ row / c4))和($ t / row / c178 [@ m = 82] =“ USA”))然后将节点$ t / row / c4的值替换为(“曼哈顿“)else(),
如果((fn:exists(/ row / c5))和($ t / row / c178 [@ m = 82] =“ USA”))然后用concat()替换节点$ t / row / c5的值“ NY 10036,USA。”,$ t / row / @ id)else()
)
返回$ t
'
传递t1.xmlrecord
返回内容
);