首页 > 数据库技术 > 详细

Oracle学习笔记:update的字段中包括单引号

时间:2019-12-20 02:08:09      阅读:484      评论:0      收藏:0      [点我收藏+]

平时update的时候直接更改字段内的值,例如:

update table_temp set name = 'Hider' where id = 100;

但更新后的值中包括单引号,则不能按以上方式进行更新,会报错。

遂测试之。

-- 建立测试表
create table temp_cwh_test_1219
(
  id varchar2(10),
  name varchar2(20)
);

-- 插入数据
insert into temp_cwh_test_1219 values (1,'Nick');
insert into temp_cwh_test_1219 values (2,'Tom');

-- 更新数据
update temp_cwh_test_1219 set name = '''xxxx''' where id = 1;
-- 1    1   'xxxx'
-- 2    2   Tom

-- 删除测试表
drop table temp_cwh_test_1219;

效果如预期。

原理:只需将需插入或更新的内容中的单引号替换为两个单引号即可。

Oracle学习笔记:update的字段中包括单引号

原文:https://www.cnblogs.com/hider/p/12070676.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!