开发提了一个需求,需要往模板表中插入包含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. Spring对外部属性文件指定的某个属性进行加密、解密

    [From] http://blog.csdn.net/ethanq/article/details/7333897 在我们开发当中,经常会用到spring框架来读取属性文件的属性值,然后使用占位符引 ...

  2. java c c++大学补遗

    第一次面试时的问题是一个看起来50多数的老工程师问的, 仍然记忆犹新 java(面向对象)的基本特性? 封装 继承 多态 工作几年后,各种框架用来用去, 回想起这个问题,java也就剩下这几个特性了

  3. JS 判断节点类型

    节点类型的分类 节点类型 说明 值 元素节点 每一个HTML标签都是一个元素节点,如 <div> . <p>.<ul>等 1 属性节点 元素节点(HTML标签)的属 ...

  4. 初探angular

    前言 angular4.0目前已经发布了,angular是mvw框架,所以对其有一个简单的了解还是很有必要的. 目前angular有中文官网,且文档介绍也都是4.x的,但是为了了解其发展过程,我们先了 ...

  5. 重入锁--ReentrantLock

    本部分主要参考<java并发编程艺术>一书相关内容,同时参考https://blog.csdn.net/zhilinboke/article/details/83104597,说的非常形象 ...

  6. 你还在把Java当成Android官方开发语言吗?Kotlin了解一下!

    导语:2017年Google IO大会宣布使用Kotlin作为Android的官方开发语言,相比较与典型的面相对象的JAVA语言,Kotlin作为一种新式的函数式编程语言,也有人称之为Android平 ...

  7. FZU 2122 ——又见LKity——————【KMP字符串匹配】

    Problem 2122 又见LKity Accept: 413    Submit: 1425Time Limit: 1000 mSec    Memory Limit : 32768 KB  Pr ...

  8. Shader学习笔记

    Shader学习笔记 例子: Shader "SrfShader1"{ //定义显示在Inspector中的变量,并从Inspector中获取值 Properties{ _Colo ...

  9. sql 行列转换

    create table #test1(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int) insert into #test1 valu ...

  10. linux shell基础编程2

    while循环 语法1: while [ 条件 ] do 命令序列 done 语法2: while read -r line do 命令序列 done (切记while和左中括号一定要有空格) 例子 ...