游标定义如下: SELECT xxx,yyy,zzz FROM tablename WHERE YY = p_StartDate AND ADDVNM = p_Region; 但有一个问题,如果我的select的列名有一个不确定,但在下面的我又要用到这个字段,该怎么办?如zzz,我不能确定它是哪个字段,要通过参数来确定,能实现吗?:(
create or replace procedure name_pro(p_col varchar2,....)
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;
/
在存储过程里使用动态游标行吗?因为zzz是传进来的一个参数,这样写
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?