本文介绍了PL/SQL,如何转义字符串中的单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Oracle PL/SQL中,如何对字符串中的单引号进行转义?我以这种方式尝试过,但是没有用.
In the Oracle PL/SQL, how to escape single quote in a string ? I tried this way, it doesn't work.
declare
stmt varchar2(2000);
begin
for i in 1021 .. 6020
loop
stmt := 'insert into MY_TBL (Col) values(\'ER0002\')';
dbms_output.put_line(stmt);
execute immediate stmt;
commit;
end loop;
exception
when others then
rollback;
dbms_output.put_line(sqlerrm);
end;
/
推荐答案
您可以使用文字引号:
stmt := q'[insert into MY_TBL (Col) values('ER0002')]';
文字文档可在此处找到.
或者,您可以使用两个引号来表示单个引号:
Alternatively, you can use two quotes to denote a single quote:
stmt := 'insert into MY_TBL (Col) values(''ER0002'')';
IMO带有Q语法的文字引用机制更加灵活和易读.
The literal quoting mechanism with the Q syntax is more flexible and readable, IMO.
这篇关于PL/SQL,如何转义字符串中的单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!