如何在 Oracle PL/SQL 中将 <、> 和 & 字符转义为 html 实体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3053090/
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
How to escape <, >, and & characters to html entities in Oracle PL/SQL
提问by SWilk
I need to send HTML emails directly from oracle PL/SQL package. This works almost fine.
我需要直接从 oracle PL/SQL 包发送 HTML 电子邮件。这几乎可以正常工作。
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.
我对从表中提取的某些数据包含诸如<S>
、<L>
和类似片段之类的内容有疑问,这些片段有时被视为 HTML 标记,即使不是,它们也总是被忽略并且从不显示。
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('<', '<', string)
manually all the special characters?
是否有自动将 html 特殊字符转义为实体的功能?还是我需要replace('<', '<', string)
手动输入所有特殊字符?
回答by Tony Andrews
You can use the htf.escape_sc function:
您可以使用 htf.escape_sc 函数:
SQL> select htf.escape_sc('Please escape <this> tag') from dual;
HTF.ESCAPE_SC('PLEASEESCAPE<THIS>TAG')
------------------------------------------------------------------
Please escape <this> tag
回答by Tim Funk
Also available is DBMS_XMLGEN.CONVERT which can handle a clob.
还可以使用 DBMS_XMLGEN.CONVERT,它可以处理一个clob。
Example:
例子:
select DBMS_XMLGEN.CONVERT('<foo>') from dual
Details: https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_xmlgen.htm
详情:https: //docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_xmlgen.htm