我有一個使用Oracle開發的查詢。我想更新同一列如何爲這個Oracle查詢應用一種循環?
'5'次。以下是我公司開發的查詢:
MERGE INTO product pr
USING(
SELECT pr.uuid,
xmltype(pr.attributes_de_de).extract('//attr[@name = "SellingPoint1"]/string/text()') AS sellingpoint1,
xmltype(pr.attributes_de_de).extract('//attr[@name = "SellingPoint2"]/string/text()') AS sellingpoint2,
xmltype(pr.attributes_de_de).extract('//attr[@name = "SellingPoint3"]/string/text()') AS sellingpoint3,
xmltype(pr.attributes_de_de).extract('//attr[@name = "SellingPoint4"]/string/text()') AS sellingpoint4,
xmltype(pr.attributes_de_de).extract('//attr[@name = "SellingPoint5"]/string/text()') AS sellingpoint5
FROM product pr WHERE pr.defaultproductvariationid ='1tap_vEBvuEAAAE89CgjnPbb' AND pr.typecode = '16'
) defaultproducts ON (pr.uuid = '8d2p_vEBCJgAAAE8ruYjnPba')
WHEN MATCHED THEN
UPDATE SET pr.attributes_de_de = CASE WHEN sellingpoint1 IS NOT NULL THEN
CASE WHEN (SELECT count(1) existscount FROM product pr
WHERE pr.uuid = '8d2p_vEBCJgAAAE8ruYjnPba'
AND existsNode(xmltype(pr.attributes_de_de), '/attrs/attr[@name="SellingPoint1"]') = 1) = 1
THEN
UPDATEXML(XMLTYPE.createXML(pr.attributes_de_de),'/attrs/attr[@name = "SellingPoint1"]/string/text()',
sellingpoint1).getClobVal()
ELSE
APPENDCHILDXML(xmltype(pr.attributes_de_de), 'attrs/attr[@name="SellingPoint22"]',
XMLType('<string>test</string>')).getClobVal()
END
ELSE
DELETEXML(xmltype(pr.attributes_de_de), '/attrs/attr[@name="SellingPoint1"]').getClobVal()
END
DELETE where pr.uuid != '8d2p_vEBCJgAAAE8ruYjnPba'
在此查詢的挑戰是列 'pr.attribute_de_de' 應該sellingpoint1,sellingpoint2,sellingpoint3,sellingpoint4,sellingpoint5更新。在oracle中如何做到這一點。非常感謝你的任何建議
非常感謝你的回覆,我不想每次更新五行,我想爲(int i = 0; i <5; i ++){'sellingpoint'+ i}做一些這樣的事情,這樣它生成sellingpoint1,sellingpoint2,....我正在尋找甲骨文解決方案 – user964147 2013-02-22 00:59:19
對不起,我誤解了你的問題。恐怕我不是100%(當我需要它的時候我會重新學習它,這種情況並不常見,然後我會在一段時間後忘記它),所以希望對MERGE更熟悉的人可以跳轉在。 – 2013-02-22 01:15:11