1、在oracle字符串('......')中使用''(两个连续的单引号'')表示单引号
SYS@orcl> select '''' from dual;
(注:最外面的两个黑色的单引号是相互匹配的,表示是oracle字符串;而里面的连续的两个红色单引号一起来代表字符串中的一个单引号)
'
-
'
Example (1):
使用单引号来转义,如: sql='select * from table where name=''' || v_test || '''' 。
Example (2) :
declare
l_name varchar2(20);
v_sql varchar2(300);
begin
v_sql := 'select ename from dept where location=''NewYork''';
execute immediate v_sql into l_name;
dbms_output.put_line(l_name);
end;
Example (3):
declare
l_name varchar2(20);
l_loc varchar2(20) := 'NewYork';
v_sql varchar2(300);
begin
v_sql := 'select ename from dept where location = ''' || l_loc || '''';
execute immediate v_sql into l_name;
dbms_output.put_line(l_name);
end;
2、使用chr(39)代表单引号
SYS@orcl> select chr(39) from dual;
C
-
'
sql = 'select * from table where name = ' || chr(39) || v_test || chr(39) ;
:
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27042095/viewspace-739412/ ,如需转载,请注明出处,否则将追究法律责任。