Oracle updateXml “less than sign” as text

十年热恋 提交于 2020-01-05 02:47:34

问题


I have xml document

<d>
  <r>a&lt;b</r>
</d>

and I want to update it to

<d>
  <r>a&lt;b or c&gt;d</r>
</d>

using updateXML statement.

Executing

select updateXML(xmltype('<d><r>a&lt;b</r></d>'),
                 '/d/r[1]/text()',
                 'a&lt;b or c&gt;d')
  from dual;

returns

<d>
  <r>a&amp;lt;b or c&amp;gt;d</r>
</d>

It is not good because of "&".

Executing

select updateXML(xmltype('<d><r>a&lt;b</r></d>'),
                 '/d/r[1]/text()',
                 'a<b or c>d')
  from dual;

throws

ORA-31067 XML nodes must be updated with valid nodes and of the same type.

How can I reach expected result?

EDIT: ORA-31067 is raised only in 10g database. It is correct query in 11g.

EDIT2: Error raised on 10.2.0.3 version and does not raised on 10.2.0.5. May by it was a bug?


回答1:


You can use this ugly workaround:

select dbms_xmlgen.convert(updateXML(xmltype('<d><r>a&lt;b</r></d>'),
                 '/d/r[1]/text()',
                 'a&lt;b or c&gt;d').getStringVal(), 1)
from dual;


来源:https://stackoverflow.com/questions/17020423/oracle-updatexml-less-than-sign-as-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!