1

我有下表结构

身份证号码

xmlData xml

我希望 xml 列 (xmlData) 中的数据根据​​以下条件更新为新值。下面是 xml 列中的示例数据。

<customer>
  <name display="CName">abc</name>
  <customerId display="CID">123</customerId>
</customer>

我的表中的某些行可能没有 customerId xml 标签,我想识别这些行并需要使用 customerId 更新 xml 标签

请建议,我该怎么做。

谢谢,

4

1 回答 1

0

modify() 方法(xml 数据类型)insert (XML DML)一起使用。

update YourTable
set xmlData.modify('insert <customerId display="CID">123</customerId> 
                    into customer[1]')
where xmlData.exist('/customer/customerId') = 0

在 where 子句中使用exists() 方法(xml 数据类型),因此您只更新没有customerId节点的行。

于 2012-12-13T11:43:49.103 回答