1

xmlファイルの単一ノードを更新するトリガーを作成したいと思います。2行のテーブルがあります。1つはエントリのIDで、もう1つはxmlタイプです。

drop table product_information_xml;
create table product_information_xml(
information_id Number(6,0),
products XMLType);

したがって、1つのエントリは次のようになります

"INFORMATION_ID"    "PRODUCTS"
5                  <products>
                       <product_id>1</product_id>
                       <product_name>samsung galaxy note</product_name>
                       <product_description>mobile phone</product_description>
                       <category_id>11</category_id>
                       <weight_class>2</weight_class>
                       <warranty_period>+000000000-06</warranty_period>
                       <supplier_id>102069</supplier_id>
                       <product_status>orderable</product_status>
                  <list_price>500</list_price>
                  <min_price>400</min_price>
                  <catalog_url>www.samsung.de</catalog_url>
              </products>

これで、xmlではない別のテーブルができました。そして、すべてのXMLタグを単一の列として持っています。したがって、列はproduct_idproduct_descriptionなどです。

更新するとき、xmlテーブルproduct_idのxmlノードを更新するにはどうすればよいですか?<product_id>誰か助けてもらえますか?

私がまだ知っていることは、私が

Create or replace trigger delete_xml
after update on product_information
for each row
begin
update ?????
end;

今、私は立ち往生しています。私は助けが欲しいです!

4

2 に答える 2

0

そのため、トリガーのステートメントは次のようになります。

product_idがnull許容でない場合:

update product_information_xml
     set products = updatexml(products, '/products/product_id/text()', :new.product_id)
   where information_id = :new.information_id;

そうである場合は、より長い方法を使用します(updatexmlはNULLから非NULLに移行しても機能しないため:

update product_information_xml
     set products = insertxmlbefore(deletexml(products, '/products/product_id'), 
                         '/products/product_name', 
                        xmltype('<product_id>' || :new.product_id|| '</product_id>'))
   where information_id = :new.information_id;
于 2012-11-11T11:55:45.807 に答える
0

更新するノードがわからない場合は、XMLTYPE全体を更新する方が簡単かもしれません-

update product_information_xml
   set products = xmltype('<products><product_id>'||:new.product_id||'</product_id>'||
                   '<product_name>'|| :new.product_name||'</product_name>'||
                   '<product_description>'|| :new.product_description||'</product_description>'||
                   '<category_id>'|| :new.category_id||'</category_id>'||
                   '<weight_class>'|| :new.weight_class||'</weight_class>'||
                   '<warranty_period>'|| :new.warranty_period||'</warranty_period>'||
                   '<supplier_id>'|| :new.supplier_id||'</supplier_id>'||
                   '<product_status>'|| :new.product_status||'</product_status>'||
                   '<list_price>'|| :new.list_price||'</list_price>'||
                   '<min_price>'|| :new.min_price||'</min_price>'||
                   '<catalog_url>'|| :new.catalog_url||'</catalog_url></products>')
 where information_id = :new.information_id;
于 2012-11-11T12:30:13.320 に答える