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

解决方案 »

  1.   

    使用动态sql,可以动态生成string,然后再执行这条语句。下面是一个例子:
    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;
      

  2.   

    DBMS_SQL怎么用在存储过程里?在存储过程里使用动态游标行吗?因为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?
      

  3.   

    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;
    /
      

  4.   

    原来在定义游标的时候SELECT里面能用变量呀?如果这样的话问题就简单多了!
    多谢上面的仁兄!:)