You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将HTML代码转换为PL/SQL?两种常见生成方式的具体实现方法是什么

HTML转PL/SQL实现方案

方式1:逐行调用HTP.PRINT

直接拆分HTML为独立行,每一行通过HTP.PRINT输出,需将字符串内的单引号替换为两个单引号完成PL/SQL转义。

BEGIN
  HTP.PRINT('<div class=''hsftic_cui_banner'' style=''text-align:center;margin:auto;width:35%;z-index:2147483647; padding: 7px;background-color: #ff9800;color: white;''>');
  HTP.PRINT('<span class=''cui_closebtn'' style=''margin-left: 15px;color: white;font-weight: bold;float: right;font-size: 18px;line-height: 20px;cursor: pointer;transition: 0.3s;'' onclick="this.parentElement.style.display=''none'';">');
  HTP.PRINT('&times;');
  HTP.PRINT('</span>');
  HTP.PRINT('<strong>System contains Controlled Unclassified Information (CUI)</strong>');
  HTP.PRINT('</div>');
END;
/

方式2:管道符||拼接后单次调用

将所有HTML片段用||拼接为完整字符串后,仅调用一次HTP.PRINT输出,同样需要转义单引号,内容过长时可将字符串变量声明为CLOB类型避免长度超限。

DECLARE
  v_html VARCHAR2(32767);
BEGIN
  v_html := '<div class=''hsftic_cui_banner'' style=''text-align:center;margin:auto;width:35%;z-index:2147483647; padding: 7px;background-color: #ff9800;color: white;''> '
         || '<span class=''cui_closebtn'' style=''margin-left: 15px;color: white;font-weight: bold;float: right;font-size: 18px;line-height: 20px;cursor: pointer;transition: 0.3s;'' onclick="this.parentElement.style.display=''none'';"> '
         || '&times;'
         || '</span>'
         || '<strong>System contains Controlled Unclassified Information (CUI)</strong>'
         || '</div>';
  HTP.PRINT(v_html);
END;
/

两种方式的mod_plsql渲染差异

  • 逐行调用HTP.PRINT:mod_plsql会在每一行输出末尾自动添加换行符,最终生成的HTML源码为分行结构,可读性更高,长内容输出时内存占用更低,不需要一次性存储全量HTML字符串。
  • 拼接后单次调用:mod_plsql会一次性输出完整字符串,不会额外插入换行符,最终HTML源码为连续单一行,输出体积更小,需注意VARCHAR2类型最大32767字节的长度限制,超出需要改用CLOB处理。

内容的提问来源于stack exchange,提问作者Chris M

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 03:15:04