如何更新oracle中clob列的xml中的特定属性

时间:2014-09-08 11:39:35

标签: xml oracle clob

我有一个CLOB列,我需要更新xml(CLOB)中某个属性的值。例如

<discounts>
                    <code>ZSP3M</code>
                    <description>50% discount 3 months</description>
                    <discountAmount>0</discountAmount>
                    <discountPercent>0.50</discountPercent>
                    <amount>0</amount>
                    <financeCode>PROMOS</financeCode>
                    <startDate>2014-04-01T00:00:00.000Z</startDate>
                    <enddate>2014-06-30T00:00:00.000Z</enddate>
                    <discountType>Group</discountType>
                    <tax>0</tax>
                    <sequenceid>1</sequenceid>
                    <discountDuration>0</discountDuration>
</discounts>

我需要更新<discountAmount>0</discountAmount> with <discountAmount>200</discountAmount>

我试过像

这样的东西
update order set order_xml = to_clob(' <?xml version="1.0" encoding="UTF-8" standalone="yes"?><discounts>
                    <code>ZSP3M</code>
                    <description>50% discount 3 months</description>
                    <discountAmount>0</discountAmount>
                    <discountPercent>0.50</discountPercent>
                    <amount>0</amount>
                    <financeCode>PROMOS</financeCode>
                    <startDate>2014-04-01T00:00:00.000Z</startDate>
                    <enddate>2014-06-30T00:00:00.000Z</enddate>
                    <discountType>Group</discountType>
                    <tax>0</tax>
                    <sequenceid>1</sequenceid>
                    <discountDuration>0</discountDuration>
</discounts>') where ordernumber = 'XXXX';

它适用于小xml,我不想更新完整的xml insted只想更新xml的属性。

1 个答案:

答案 0 :(得分:0)

如果将XML存储为CLOB,除了重写整个CLOB值之外别无他法。

但是,如果您将XML存储为XMLTYPE,则可以使用Oracle XML DB的完整XPath功能,包括XQuery Update。看看this question on SO.