就是 动态sql语句 v_sqk:='select * from tb where name='swith' ';这个在plsql的存储过程里面如何转义'单引号啊?
我的存储过程小实例如下:
create or replace zz
as
v_sql varchar2(2000);
begin
v_sql:=' select * from scott.emp where name='swith' ';
open cursor c1 v_sql;
end zz;我不太习惯用chr(39),还有别的办法没有啊?
我的存储过程小实例如下:
create or replace zz
as
v_sql varchar2(2000);
begin
v_sql:=' select * from scott.emp where name='swith' ';
open cursor c1 v_sql;
end zz;我不太习惯用chr(39),还有别的办法没有啊?
as
v_sql varchar2(2000);
begin
v_sql:=' select * from scott.emp where name=''swith'' ';
open cursor c1 v_sql;
end zz;
v_sql:=q'<select * from scott.emp where name='swith'> ';
是一个很不好的习惯,应该使用绑定变量using,如果你使用动态SQL的话。
你想想,使用绑定变量,还存在这些乱七八糟的问题吗??对于字符串中引号的处理,我建议使用chr(39),比q-quote要好
SQL> select 'tom'||chr(39)||' book' from dual;
'TOM'||CHR(39)||'BOOK'
----------------------
tom' book看看,你还会被引号困扰吗?
chr(39) 函数对应的是OARCLE 里面的'。你可以用这个函数来代替。