平時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;
效果如預期。
原理:只需將需插入或更新的內容中的單引號替換為兩個單引號即可。