How to escape <, >, and & characters to html entities in Oracle PL/SQL

不问归期 提交于 2019-11-29 11:48:39

问题


I need to send HTML emails directly from oracle PL/SQL package. This works almost fine.

I have problem with the fact that some of the data fetched from a table contain things like <S>, <L>, and similar fragments, which sometimes ar treated as HTML tags, and even if not, they are always ignored and never displayed.

So, I need to escape this column before inserting into email body.

Is there a function to escape html special chars into entities automaticly? Or do I need to replace('<', '&lt;', string) manually all the special characters?


回答1:


You can use the htf.escape_sc function:

SQL> select htf.escape_sc('Please escape <this> tag') from dual;

HTF.ESCAPE_SC('PLEASEESCAPE<THIS>TAG')
------------------------------------------------------------------
Please escape &lt;this&gt; tag



回答2:


Also available is DBMS_XMLGEN.CONVERT which can handle a clob.

Example:

select DBMS_XMLGEN.CONVERT('<foo>') from dual

Details: https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_xmlgen.htm



来源:https://stackoverflow.com/questions/3053090/how-to-escape-and-characters-to-html-entities-in-oracle-pl-sql

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