开发提了一个需求,需要往模板表中插入包含html代码的记录,表的ddl如下

create table WZ_SITEMSGTEMPLATE
(
id NUMBER(19) not null,
templatecontent NCLOB,
createtime DATE,
modeltype NUMBER(10) default (1)
)

  html代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body,
div,
p,
a,
img,
span,
h2 {
margin: 0;
padding: 0;
}
body {
line-height: 1;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
}
a {
text-decoration: none;
}
img {
border: 0;
}
.clearfix {
overflow: hidden;
zoom: 1;
}
.container--yx {
width: 750px;
margin: 0 auto;
}
.container--yx .top_bar {
height: 96px;
padding: 0 24px;
}
.container--yx .top_bar .logo_box {
float: left;
width: 263px;
height: 37px;
padding-top: 30px;
}
.container--yx .top_bar .qrcode_box {
width: 213px;
float: right;
padding-top: 18px;
}
.container--yx .top_bar .qrcode_box .qrcode_pic {
float: left;
width: 62px;
height: 62px;
margin-right: 10px;
}
.container--yx .top_bar .qrcode_box .qrcode_text {
float: right;
}
.container--yx .top_bar .qrcode_box .qrcode_text .lg_text {
font-size: 23px;
font-weight: bold;
}
.container--yx .top_bar .qrcode_box .qrcode_text .lg_text .red_text {
color: #bd2230;
}
.container--yx .banner {
position: relative;
width: 100%;
height: 458px;
background: url('http://static.xxxxxxxx.com/images/yx_banner.jpg') no-repeat;
background-size: 100% 458px;
}
.container--yx .banner .price {
position: absolute;
top: 64px;
left: 140px;
color: #fff;
}
.container--yx .banner .price .mark {
position: absolute;
top: 26px;
font-size: 82px;
font-family: 'Microsoft Yahei';
vertical-align: top;
}
.container--yx .banner .price .num {
position: absolute;
left: 82px;
font-size: 238px;
font-family: 'Arial, Helvetica, sans-serif';
}
.container--yx .banner .draw_coupon {
position: absolute;
top: 124px;
right: 124px;
}
.container--yx .banner .draw_coupon .coupon_title {
color: #fff;
font-size: 36px;
margin-bottom: 20px;
}
.container--yx .banner .draw_coupon .coupon_btn {
padding: 5px 24px;
color: #333;
background: #fff;
}
.container--yx .banner .down_box {
position: absolute;
top: 310px;
padding: 0 84px;
color: #fff;
line-height: 30px;
}
.container--yx .new_active {
background: #f8f8f8;
padding-bottom: 30px;
}
.container--yx .new_active h2 {
font-size: 24px;
line-height: 68px;
text-align: center;
font-weight: normal;
}
.container--yx .new_active .wrap {
padding: 0 14px;
}
.container--yx .new_active .wrap img {
width: 235px;
height: 112px;
}
</style>
</head>
<body>
<div class="container--yx">
<div class="top_bar clearfix">
<img class="logo_box" src="http://static.xxxxxxxx.com/images/yx_logo.png" alt="">
<div class="qrcode_box clearfix">
<img class="qrcode_pic" src="http://static.xxxxxxxx.com/images/yx_qrcode.png" alt="">
<div class="qrcode_text">
<p>首次下载App</p>
<div class="lg_text">
<p class="red_text">领188元</p>
<p>时尚礼包</p>
</div>
</div>
</div>
</div>
<div class="banner">
<div class="up_box">
<div class="price">
<span class="mark">¥</span>
<span class="num">#lqamt#</span>
</div>
<div class="draw_coupon">
<p class="coupon_title">网龄券</p>
<a class="coupon_btn" href="http://member.xxxxxxxx.com/Acct/Promotion">点击领取 > </a>
</div>
</div>
<div class="down_box">
<p>
#lqcontent#
</p>
</div>
</div>
<div class="new_active">
<h2>最新活动</h2>
<div class="wrap">
<a href="javascript:;">
<img src="http://static.xxxxxxxx.com/images/yx_pic01.jpg" alt="">
</a>
<a href="javascript:;">
<img src="http://static.xxxxxxxx.com/images/yx_pic02.jpg" alt="">
</a>
<a href="javascript:;">
<img src="http://static.xxxxxxxx.com/images/yx_pic03.jpg" alt="">
</a>
</div>
</div>
<div class="footer_bar">
<img src="http://static.xxxxxxxx.com/images/yx_bd.jpg" alt="">
</div>
</div>
</body>
</html>

  直接使用语句插入的时候,出现了“ORA-01756:引号内的字符串没有正确结束”的错误。

  我把代码截断一下,不用看起来那么费劲,重现一下错误

select  '[<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body,
div,
p,
a,
img,
span,
h2 {
margin: 0 ;
padding: 0;]'
from dual;

  上面的代码,无论是在PL/SQL Developer里执行,还是在linux终端的sqlplus里执行,都是一样的错误。

  有2个情况需要在这里说明一下

    一、在linux终端的sqlplus里执行的时候,修改一下sqlterminator为非';'的值,就能正常执行。

    二、我的PL/SQL Developer(版本:9.0.6)执行报错,但是旁边同事的PL/SQL Developer(版本:11.0.x)就执行成功,不确定是不是版本的问题,也可能是首选项或者其他配置的差异,至今没找到差异在哪里。

  google了一下,也没有搜索到答案,最终郑松华大师给了一个解决方法

select  '[<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body,
div,
p,
a,
img,
span,
h2 {
margin: 0 '||';'||'
padding: 0;]'
from dual;

  原因是在oracle里,“;+换行”就是代表执行,所以就会提示上面的错误。但是让我疑惑的是,在字符串内的,为什么会执行?不到“'”结束,也只是一段字符串而已。

  此方法一;

  补充:

  因为html代码太长,使用这种方法插入到列的时候,会提示“ORA-01489:字符串连接的结果过长”。其中原因是把这些代码当做字符串来拼接,最大的长度不能超过varchar2的长度,解决方法是:把代码分开转换成nclob类型,再进行拼接,完整例子如下:

select seq_wz_sitemsgtemplate.nextval,
to_nclob('<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body,
div,
p,
a,
img,
span,
h2 {
margin: 0'||';'||'
padding: 0'||';'||'
}
body {
line-height: 1'||';'||'
font-family: Arial, Helvetica, sans-serif'||';'||'
font-size: 16px'||';'||'
}
a {
text-decoration: none'||';'||'
}
img {
border: 0'||';'||'
}
.clearfix {
overflow: hidden'||';'||'
zoom: 1'||';'||'
}
.container--yx {
width: 750px'||';'||'
margin: 0 auto'||';'||'
}
.container--yx .top_bar {
height: 96px'||';'||'
padding: 0 24px'||';'||'
}
.container--yx .top_bar .logo_box {
float: left'||';'||'
width: 263px'||';'||'
height: 37px'||';'||'
padding-top: 30px'||';'||'
}
.container--yx .top_bar .qrcode_box {
width: 213px'||';'||'
float: right'||';'||'
padding-top: 18px'||';'||'
}
.container--yx .top_bar .qrcode_box .qrcode_pic {
float: left'||';'||'
width: 62px'||';'||'
height: 62px'||';'||'
margin-right: 10px'||';'||'
}
.container--yx .top_bar .qrcode_box .qrcode_text {
float: right'||';'||'
}
.container--yx .top_bar .qrcode_box .qrcode_text .lg_text {
font-size: 23px'||';'||'
font-weight: bold'||';'||'
}
.container--yx .top_bar .qrcode_box .qrcode_text .lg_text .red_text {
color: #bd2230'||';'||'
}
.container--yx .banner {
position: relative'||';'||'
width: 100%'||';'||'
height: 458px'||';'||'
background: url(''http://static.xxxxxxxx.com/images/yx_banner.jpg'') no-repeat'||';'||'
background-size: 100% 458px'||';'||'
}
.container--yx .banner .price {
position: absolute'||';'||'
top: 64px'||';'||'
left: 140px'||';'||'
color: #fff'||';'||'
}
.container--yx .banner .price .mark {
position: absolute'||';'||'
top: 26px'||';'||'
font-size: 82px'||';'||'
font-family: ''Microsoft Yahei' || ''||';'||'
vertical-align: top'||';'||'
}
.container--yx .banner .price .num {
position: absolute'||';'||'
left: 82px'||';'||'
font-size: 238px'||';'||'
font-family: ''Arial, Helvetica, sans-serif' || ''||';'||'
}
.container--yx .banner .draw_coupon {
position: absolute'||';'||'
top: 124px'||';'||'
right: 124px'||';'||'
}
.container--yx .banner .draw_coupon .coupon_title {
color: #fff'||';'||'
font-size: 36px'||';'||'
margin-bottom: 20px'||';'||'
}
.container--yx .banner .draw_coupon .coupon_btn {
padding: 5px 24px'||';'||'
color: #333'||';'||'
background: #fff'||';'||'
}
.container--yx .banner .down_box {
position: absolute'||';'||'
top: 310px'||';'||'
padding: 0 84px'||';'||'
color: #fff'||';'||'
line-height: 30px'||';'||'
}
.container--yx .new_active {
background: #f8f8f8'||';'||'
padding-bottom: 30px'||';'||'
}
.container--yx .new_active h2 {
font-size: 24px'||';'||'
line-height: 68px'||';'||'
text-align: center'||';'||'
font-weight: normal'||';'||'
}
.container--yx .new_active .wrap {
padding: 0 14px'||';'||'
}
.container--yx .new_active .wrap img {
width: 235px'||';'||'
height: 112px'||';'||'
}
</style>
</head>') || to_nclob('
<body>
<div class="container--yx">
<div class="top_bar clearfix">
<img class="logo_box" src="http://static.xxxxxxxx.com/images/yx_logo.png" alt="">
<div class="qrcode_box clearfix">
<img class="qrcode_pic" src="http://static.xxxxxxxx.com/images/yx_qrcode.png" alt="">
<div class="qrcode_text">
<p>首次下载App</p>
<div class="lg_text">
<p class="red_text">领188元</p>
<p>时尚礼包</p>
</div>
</div>
</div>
</div>
<div class="banner">
<div class="up_box">
<div class="price">
<span class="mark">¥</span>
<span class="num">#lqamt#</span>
</div>
<div class="draw_coupon">
<p class="coupon_title">网龄券</p>
<a class="coupon_btn" href="http://member.xxxxxxxx.com/Acct/Promotion">点击领取 > </a>
</div>
</div>
<div class="down_box">
<p>
#lqcontent#
</p>
</div>
</div>
<div class="new_active">
<h2>最新活动</h2>
<div class="wrap">
<a href="javascript:'||';'||' ">
<img src="http://static.xxxxxxxx.com/images/yx_pic01.jpg" alt="">
</a>
<a href="javascript:'||';'||' ">
<img src="http://static.xxxxxxxx.com/images/yx_pic02.jpg" alt="">
</a>
<a href="javascript:'||';'||' ">
<img src="http://static.xxxxxxxx.com/images/yx_pic03.jpg" alt="">
</a>
</div>
</div>
<div class="footer_bar">
<img src="http://static.xxxxxxxx.com/images/yx_bd.jpg" alt="">
</div>
</div>
</body>
</html>') ,
sysdate,
2
from dual;

  方法二:先插入其他的列,在使用select …… for update来粘贴html代码列。

select * from wz_sitemsgtemplate where id = 4388 for update  ;

  以上,如有错谬,请不吝指正。

Oracle往列中插入html代码的更多相关文章

  1. 在Latex中插入Python代码

    这里指的插入是指最终能在生成的pdf中显示高亮的Python代码. 在Latex中插入Python代码,需要一个第三发的宏包pythonhighlight: https://github.com/ol ...

  2. 使用<script>标签在HTML网页中插入JavaScript代码

    新朋友你在哪里(如何插入JS) 我们来看看如何写入JS代码?你只需一步操作,使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要 ...

  3. html中插入flash代码详解(转载)

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...

  4. 在网页中插入背景音乐代码(html)

    有两种 分别用<bgsound>和<embed></embed>标签,当用<embed>插入背景音乐时可以设置宽度和高度为0,隐藏播放器. 二者的参数如 ...

  5. beamer中插入c代码,python代码的经验

    下面是插入的scala代码,它与python在某些语法上类似,所在在https://github.com/olivierverdier/python-latex-highlighting下载了一个py ...

  6. Oracle根据列中的特殊符号进行分组

    原数据: 目标结果: 根据-符号将数据进行分组,思路是根据NAME列值进行复制,若为‘-’则赋值1,其他为0,这样就可以根据累加实现分组, 具体实现代码: /* Formatted on 2019/9 ...

  7. oracle 向表中插入BLOB类型数据

    提示: 待插入图片必须保存到oracle主机路径上. 步骤: 1.SYSDBA权限用户创建图片所在目录 CREATE OR REPLACE DIRECTORY TEST_DIR AS 'C:\Pict ...

  8. 向Oracle 数据表中插入一条带有日期类型的数据

    有一张表:batch(批次表) 表的字段如下: 第一种情况: 现在需要插入一条当前的系统时间 sql 如下: insert into batch (batch_id, cus_id, batch_nu ...

  9. oracle一列中的数据有多个手机号码用逗号隔开,我如何分别取出来?

    ID NUMBER1 137xxxx,138xxxx取出来成ID NUMBER1 137xxxx1 138xxxx create table test (id int, phone varchar2( ...

随机推荐

  1. P3066 [USACO12DEC]逃跑的BarnRunning Away From (树上二分)

    题意 给出以1号点为根的一棵有根树,问每个点的子树中与它距离小于等于l的点有多少个. 树上二分.这个做法还是基于树上差分的,也就是对于每一个点uu,我们要找到它向上跳LL的长度最高能够跳到的祖先.(当 ...

  2. HDU - 4825 01字典树套路题

    /*H E A D*/ struct Trie{ int son[maxn<<2][2]; int b[67],tot; void init(){ // memset(son,0,size ...

  3. 云服务的三种形式laas,paas,saas

    “云”其实是互联网的一个隐喻,“云计算”其实就是使用互联网来接入存储或者运行在远程服务器端的应用,数据,或者服务. 云也是分层的 任何一个在互联网上提供其服务的公司都可以叫做云计算公司.其实云计算分几 ...

  4. 有用的 Angular CLI 命令参数

    这是一些有用的 Angular 5 CLI 命令参数,注意参数前面的-和--的不同... 1. 指定build的输出为production version,合并优化css and js files. ...

  5. [转] 使用 Java8 Optional 的正确姿势

    [From] https://unmi.cc/proper-ways-of-using-java8-optional/ 我们知道 Java 8 增加了一些很有用的 API, 其中一个就是 Option ...

  6. [转] SpringBoot RESTful 应用中的异常处理小结

    [From] https://segmentfault.com/a/1190000006749441 SpringBoot RESTful 应用中的异常处理小结 永顺 2016年08月29日发布 赞  ...

  7. java.lang.ref.Reference<T>

    //看之前先要知道java里面的四种引用.package com.zby.ref; import sun.misc.Cleaner; /** * 引用对象的抽象基础类.这个类定义了所有引用对象的公共操 ...

  8. jquery将日期转换成指定格式的字符串

    引用jquery文件,如<script type="text/javascript" src="jquery-1.8.3.min.js"></ ...

  9. MAC 下 STF 的环境搭建和运行

    STF --WEB 端批量移动设备管理控制工具 安装各种包 (首先安装Macport,因为后面需要用到port:http://www.ccvita.com/434.html) linux的基本包安装, ...

  10. Best HTTP

    http://blog.csdn.net/u012322710/article/details/52860747 Best HTTP (Pro)  这是一款很多公司都在用的网页插件,感觉确实不错,分P ...