Conditionally define a Cursor

后端 未结 3 1959
鱼传尺愫
鱼传尺愫 2020-12-19 07:34

I have a Procedure in Oracle that takes a varchar2 paramater. Based on the value of that parameter, I need to define a cursor. The cursor will operate on diff

3条回答
  •  执笔经年
    2020-12-19 07:54

    You can even use the condition inside the implicit for loop. Without cursor declaration or SYS_REFCURSOR (I dislike them sorry) - I mean you can use your variables, here v_action, inside implicit cursor declaration:

    BEGIN
        FOR this_cur IN (
           SELECT * FROM  
            WHERE v_action = 'DO THIS'
        ) LOOP
          <>
        END LOOP;
        FOR that_cur IN (
           SELECT * FROM  
            WHERE v_action <> 'DO THIS'
        ) LOOP
          <>
        END LOOP;
      END IF;
    END;
    

提交回复
热议问题