oracle HTML 实体解码为特殊字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17485228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:46:48  来源:igfitidea点击:

HTML Entity decoding to Special characters

htmlsqloracle

提问by user2552670

I want to display special symbols in my output. For eg: My text may contain entity codes like &lt;, &gt; etc. I want to display this as <, >in my output. I need to do this in SQL. I googled about this and got a function,

我想在我的输出中显示特殊符号。例如:我的文本可能包含实体代码,如&lt;, &gt; 等我想在我的输出中显示为<, >。我需要在 SQL 中执行此操作。我用谷歌搜索了这个并得到了一个函数,

select dbms_xmlgen.convert('ABC <; ',0) from dual

select dbms_xmlgen.convert('ABC <; ',0) from dual

This does the reverse process, it generates the output as 'ABC <'

这是相反的过程,它生成的输出为 'ABC <'

I tried with decoding but it does not work. I even changed the sql command as, select dbms_xmlgen.convert('ABC <; ',1) from dual, where 1 is for entity_decode, but I don't get the desired output.

我尝试解码但它不起作用。我什至将 sql 命令更改为, select dbms_xmlgen.convert('ABC <; ',1) from dual,其中 1 代表entity_decode,但我没有得到所需的输出。

回答by Jako

Instead of using DBMS_XMLGEN.convert, I used the function UTL_I18N.UNESCAPE_REFERENCE:

我没有使用 DBMS_XMLGEN.convert,而是使用了函数 UTL_I18N.UNESCAPE_REFERENCE:

SELECT UTL_I18N.UNESCAPE_REFERENCE('ABC &lt; ') FROM DUAL;

result:

结果:

ABC < 

More information on the Oracle doc: http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_i18n.htm#i998992

有关 Oracle 文档的更多信息:http: //docs.oracle.com/cd/B19306_01/appdev.102/b14258/u_i18n.htm#i998992

回答by Aioros

Try something like:

尝试类似:

SELECT DBMS_XMLGEN.CONVERT('ABC &lt; ', DBMS_XMLGEN.ENTITY_DECODE) FROM DUAL

Also, see the Oracle docsfor that.

另外,请参阅Oracle 文档

EDIT:

编辑:

Ok, so apparently this is a bug in some Oracle versions (9.2.0.1 and 10.1.0.2, as it seems). Somebody solved itby wrapping the function. I don't know how that's supposed to solve it, but it my be worth trying. Create a function like this:

好的,显然这是某些 Oracle 版本(看起来是 9.2.0.1 和 10.1.0.2)中的一个错误。有人通过包装函数来解决它。我不知道这应该如何解决它,但我值得一试。创建一个这样的函数:

CREATE OR REPLACE FUNCTION
   xml_decode(
      i_xml_string IN VARCHAR2
   )
   RETURN VARCHAR2
IS
BEGIN
   RETURN
      DBMS_XMLGEN.convert(
         i_xml_string,
         DBMS_XMLGEN.ENTITY_DECODE
      );
END;

And use it instead:

并改用它:

SELECT xml_decode('ABC &lt; ') FROM DUAL;

Let us know if that works.

让我们知道这是否有效。