in StoreProcedue , You can use DBMS_SQL to define the dynamic sql . It should meet your requirement ,
All you can just code your script :if condition 1
SELECT xxx,yyy,zzz
else
SELECT xxx,yyy,zzz1
All you can just code your script :if condition 1
SELECT xxx,yyy,zzz
else
SELECT xxx,yyy,zzz1
TYPE TCursor IS REF CURSOR;
cc TCursor;
if condition 1
strSql := 'SELECT xxx,yyy,zzz1';
else
strSql := 'SELECT xxx,yyy,zzz1';
end if;
open cc for strSql;
if zzz := 'a' then
OPEN v_ADDV FOR --打开游标变量
select xxx,yyy,zzz1
end if;
if zzz := 'b' then
OPEN v_ADDV FOR --打开游标变量
select xxx,yyy,zzz2
end if;
这样OK?
as
type t_sor is ref cursor;
v_sor t_sor;
strsql varchar2(50);
begin
strsql:='SELECT xxx,yyy,'||p_col||'
FROM tablename
WHERE YY <= '||p_EndDate||' AND YY>='|| p_StartDate||' AND ADDVNM = '||p_Region;
open v_sor for strsql;
fetch v_sor into ....;
loop
exit when v_sor%notfound;
....
end loop;
....
close v_sor;
end;
/
多谢上面的仁兄!:)