Oracle updateXml“小于符号"作为文字 [英] Oracle updateXml "less than sign" as text

查看:95
本文介绍了Oracle updateXml“小于符号"作为文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有xml文档

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

,我想将其更新为

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

使用 updateXML 语句.

执行

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

返回

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

因为&"而不好.

It is not good because of "&".

执行

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

抛出

ORA-31067 XML节点必须使用有效的节点和相同类型的节点进行更新.

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

我如何达到预期的结果?

How can I reach expected result?

编辑:仅在10g数据库中引发ORA-31067.在11g中是正确的查询.

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

EDIT2 :在10.2.0.3版本上引发了错误,在10.2.0.5版本上未引发.可能是个错误吗?

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

推荐答案

您可以使用以下丑陋的解决方法:

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;

这篇关于Oracle updateXml“小于符号"作为文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆