Oracle學習筆記:update的字段中包括單引號


平時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;

效果如預期。

原理:只需將需插入或更新的內容中的單引號替換為兩個單引號即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM