procedure my_proc(p_first VARCHAR2, p_second NUMBER, p_third NUMBER DEFAULT NULL, p_fouth NUMBER DEFAULT NULL)
IS
str varchar2(3200);
v1 VARCHAR2(20);
v2 VARCHAR2(20);
v3 VARCHAR2(20);
str2 varchar2(1000);
begin
str2:='SELECT t2.c1,t2.c2, my_func1(t2.c3, '||p_third||') FROM ';
if p_third=3 then
str:= 't1,t2,t3 where t1.c1=t2.c1 and t2.c1=t3.c1 and t1.c1=p_first ;' ;
elsif p_third=2 then
str:=' t1,t2,t4 where t1.c1=t2.c1 and t2.c1=t4.c1 and t2.c1=p_second ;' ;
else
str:='t2 where t2.c1=p_second ;';
end if;
str2:=str2 || str;
dbms_output.put_line(str2);
EXECUTE IMMEDIATE str2 into v1,v2,v3;
--dbms_output.put_line(v1||','||v2||','||v3);
end;
其中pçthird为空,因此sql结果为:
SELECT t2.c1,t2.c2, my_func1(t2.c3, ) FROM t1,t2,t4 where t1.c1=t2.c1 and t2.c1=t4.c1 and t2.c1=p_second;
我需要的是:
SELECT t2.c1,t2.c2, my_func1(t2.c3) FROM t1,t2,t4 where t1.c1=t2.c1 and t2.c1=t4.c1 and t2.c1=p_second;
每当第三个是
NULL