Oracle往列中插入html代码
开发提了一个需求,需要往模板表中插入包含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代码的更多相关文章
- 在Latex中插入Python代码
这里指的插入是指最终能在生成的pdf中显示高亮的Python代码. 在Latex中插入Python代码,需要一个第三发的宏包pythonhighlight: https://github.com/ol ...
- 使用<script>标签在HTML网页中插入JavaScript代码
新朋友你在哪里(如何插入JS) 我们来看看如何写入JS代码?你只需一步操作,使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要 ...
- html中插入flash代码详解(转载)
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://down ...
- 在网页中插入背景音乐代码(html)
有两种 分别用<bgsound>和<embed></embed>标签,当用<embed>插入背景音乐时可以设置宽度和高度为0,隐藏播放器. 二者的参数如 ...
- beamer中插入c代码,python代码的经验
下面是插入的scala代码,它与python在某些语法上类似,所在在https://github.com/olivierverdier/python-latex-highlighting下载了一个py ...
- Oracle根据列中的特殊符号进行分组
原数据: 目标结果: 根据-符号将数据进行分组,思路是根据NAME列值进行复制,若为‘-’则赋值1,其他为0,这样就可以根据累加实现分组, 具体实现代码: /* Formatted on 2019/9 ...
- oracle 向表中插入BLOB类型数据
提示: 待插入图片必须保存到oracle主机路径上. 步骤: 1.SYSDBA权限用户创建图片所在目录 CREATE OR REPLACE DIRECTORY TEST_DIR AS 'C:\Pict ...
- 向Oracle 数据表中插入一条带有日期类型的数据
有一张表:batch(批次表) 表的字段如下: 第一种情况: 现在需要插入一条当前的系统时间 sql 如下: insert into batch (batch_id, cus_id, batch_nu ...
- oracle一列中的数据有多个手机号码用逗号隔开,我如何分别取出来?
ID NUMBER1 137xxxx,138xxxx取出来成ID NUMBER1 137xxxx1 138xxxx create table test (id int, phone varchar2( ...
随机推荐
- C/S架构与B/S架构的区别
什么是C/S结构和B/S结构? C/S结构 C/S结构是指Client/Server (客户机/服务器) 结构,是大家熟知的软件系统体系结构,通过将任务合理分配到Client端和Server端,降低了 ...
- java移位操作注意事项
来个浅显的 在java中,移位分为有符号移位和无符号移位,无符号移位的话不论左移还是右移,自动在低位或者高位补0 如果是有符号数进行移位的话,必须要先将
- PIXI AnimatedSprite 及打字爆炸动画(5)
效果 : 消除字母 当前位置出现爆炸效果 这里使用到了AnimatedSprite 动画 Members An AnimatedSprite is a simple way to display a ...
- zabbix_agent 主动模式配置
一,主动与被动模式 默认的模式就是被动模式由服务端发送执行指令,客户端再执行 主动模式则为客户机自己找服务器拿任务执行 二,主动模式配置 查看客户端配置文件 grep '^[a-Z]' /etc/za ...
- java与C语言在字符串结束符上的区别
综述:在C语言中字符串或字符数组最后都会有一个额外的字符‘\0’来表示结束,而在java语言中没有结束符这一概念.具体见下面分析. 1. C 语言 在C语言中字符串和字符数组基本上没有区别,都需要结束 ...
- 基于原生态Hadoop2.6 HA集群环境的搭建
hadoop2.6 HA平台搭建 一.条件准备 软件条件: Ubuntu14.04 64位操作系统, jdk1.7 64位,Hadoop 2.6.0, zookeeper 3.4.6 硬件条件 ...
- (转)SSH服务详解
SSH服务详解 原文:http://www.cnblogs.com/clsn/p/7711494.html 第1章 SSH服务1.1 SSH服务协议说明SSH 是 Secure Shell Proto ...
- jquery:字符串(string)转json
第一种方式: 使用js函数eval(); testJson=eval(testJson);是错误的转换方式. 正确的转换方式需要加(): testJson = eval("(" + ...
- 防盗链与springboot代理模式(图片文件转发)
在搭建自己的博客网站的时候,很有可能要引入一些外部图片,毕竟多数人最开始不是在自己的平台上写博客. 因某种需要,搬运自己以前写的博客到自己的网站时,在图片这一步可能会出现问题,无法显示.其中往往就是防 ...
- unity3d发布到安卓平台
1.首先你得装上JDK并且配置好环境(就像学java配置环境一样) 百度jdk把下载安装成功 找到安装jdk目录的bin目录,复制路径,例如 C:\Program Files (x86)\Java\j ...