日期:2014-05-17  浏览次数:20996 次

oralce in 查询不能传入字符串
declare
 var_catids varchar2(256) default '';
 int_pp integer default 0;

begin 

 var_catids :='1640,1633,1635';
select max(pp) into int_pp from table1 where id in (var_catids);
dbms_output.put_line('int_pp:'||int_pp);
end;

把select max(pp) into int_pp from table1 where id in (var_catids);这语句换成如下就正常了
select max(pp) into int_pp from table1 where id in (1640,1633,1635);

哪位高手帮我看看.

------解决方案--------------------
SQL code
declare 
var_catids varchar2(256) default ''; 
int_pp integer default 0; 
tem_sql varchar(2000);
begin 

var_catids :='1640,1633,1635'; 
temp_sql:='select max(pp)  from  table1 where  id in ('||var_catids||')'; 
execute immediate temp_sql into int_pp ;
dbms_output.put_line('int_pp:' ¦ ¦int_pp); 
end;

------解决方案--------------------
正解
探讨
SQL codedeclare
var_catids varchar2(256) default '';
int_pp integer default 0;
tem_sql varchar(2000);
begin

var_catids :='1640,1633,1635';
temp_sql:='select max(pp) from table1 where id in ('||var_catids||')';
execute immediate temp_sql into int_pp ;
dbms_output.put_line('int_pp:' ¦ ¦int_pp);
end;


你这样去试试看