2017-10-30 21 views
0

Oracle 10からOracle 12cへ移行する途中です。 ほとんどのデータにXmlTypeドキュメントが含まれているDBの一部を移行しました。新しい要件のため、一部の文書では属性の更新が必要です。ノードに新しい属性を追加するXMLTypeを更新します。

当初、我々はXMLを次ていますxmlupdate後

<root> 
<a id="1"> 
    aaaaaaaaaa 
</a> 
<b id="2"> 
    bbbbbbbbbb 
</b> 
</root> 

、それはこのようなものにする必要があります。Oracle 10では

<root> 
<a id="1"> 
    aaaaaaaaaa 
</a> 
<b id="2" newAttribute=""> 
    bbbbbbbbbb 
</b> 
</root> 

、これは成功するでしょう:

update TABLE_NAME set whattoUpdate = (select insertchildxml(whattoUpdate, 'xpathexpression', '@attribute', 'valueOfAttribute', 'namespace') as result from TABLE_NAME where id = XX); 

これは動作するはずですが、Oracle 12では動作しません(select文は空のxmlを01に返します)。)。

thisによれば、機能insertchildxml()はサポートされなくなりました。

答えて

1
create table example(xml clob); 

insert into example values('<root> 
<a id="1"> 
    aaaaaaaaaa 
</a> 
<b id="2"> 
    bbbbbbbbbb 
</b> 
</root>'); 

update example set xml = xmlserialize(document XMLQuery(' 
xquery version "1.0"; 
copy $cp := . 
modify 
    insert node attribute newAttribute {""} into $cp/root/a 
return $cp 
' 
passing xmltype(xml) returning content) indent size = 2); 

xmlserialize(document {xmltype} indent size =2) - xmlをclobに変更しています。
xmluqery stuctureは、入力XML文書のコピーを作成 xmlquery('xquery language' passing {xmltype} returning content)

copy $cp :=.です。元のデータを変更する方法がないために必要です。

modify insert node attribute newAttribute {""} into $cp/root/a return $cp - xqueryコマンド。選択した要素に新しい属性を追加します。

関連する問題