2017-10-30 5 views
0

오라클 10에서 오라클 12c로 마이그레이션하는 중이다. 대부분의 데이터에 XmlType 문서가 포함되어있는 DB의 일부를 마이그레이션했습니다. 새로운 요구 사항으로 인해 일부 문서에는 속성 업데이트가 필요합니다. 우리는 XML 다음 한 처음노드에 새 속성을 추가하는 XMLType 업데이트

는 :

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

오라클 (10),이 성공할 것 :

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

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

,이 같은 것을 할 필요가

이것은 제대로 작동하지만 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는 xmlquery('xquery language' passing {xmltype} returning content)

copy $cp :=. 입력 XML 문서의 복사본을 생성한다. 원본 데이터를 수정할 방법이 없기 때문에 필요합니다.

modify insert node attribute newAttribute {""} into $cp/root/a return $cp - xquery 명령. 선택한 요소에 새 속성을 추가하는 중입니다.