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( ...
随机推荐
- In linux shell, How to cp/rm files by time?
find /path/to/folder/ -mtime 1 -exec rm {} \; // Deletes all Files modified yesterday
- POJ_3696 The Luckiest number 【欧拉定理+同余式+对取模的理解】
一.题目 Chinese people think of '8' as the lucky digit. Bob also likes digit '8'. Moreover, Bob has his ...
- HDU - 1285-确定比赛名次(拓扑排序+优先队列)
有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...
- Bootstrap4 导航栏元素居右
Bootstrap 4正解: .ml-auto元素居右 .mr-auto元素居左 在某度上查了半小时还是没查出什么名堂,搜出来的方法大多都是Bootstrap3的,实测pull-right或navba ...
- AtCoder Beginner Contest 113 A
A - Discount Fare Time limit : 2sec / Memory limit : 1024MB Score: 100 points Problem Statement Ther ...
- 天梯赛easy题
2 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> ...
- 事件获取目标 currentTarget target srcElement 三者之间的区别和联系
currentTarget 指的是触发事件的当前对象,可以是冒泡和捕获的对象,不一定是点击或者鼠标移入等事件的直接触发对象.可以是他的父元素等. target 指的是事件触发的直接对象.IE有兼容 ...
- git 代码统计
查看git上的个人代码提交量: git log --author="Marek Romanowski" --since="2019-01-01" --no-me ...
- IDEA查看第三方jar包的源代码时出现Decompiled.class file, bytecode version:52.0 (Java 8)的解决方案
IDEA中使用Ctrl+左键查看第三方jar包的源代码时,出现Decompiled.class file, bytecode version:52.0 (Java 8),说明IDEA没找到该类的.ja ...
- spark第十八篇:Tuning Spark 调优
由于大多数Spark应用都是在内存中计算的,所以,Spark程序的瓶颈可能是集群中的任何资源,比如CPU,网络带宽或者内存等.本指南主要涵盖两个主题: 1.数据序列化.这对于良好的网络性能至关重要,还 ...