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
I would probably code something like this (where the two loops may call the same functions)
BEGIN
IF( v_action = 'DO THIS' )
THEN
FOR this_cur IN (SELECT * FROM )
LOOP
<>
END LOOP;
ELSE
FOR that_cur IN (SELECT * FROM )
LOOP
<>
END LOOP;
END IF;
END;
You could also use dynamic SQL to open the cursor but that tends to get more complicated, particularly if there are only two options.
IS
get_records SYS_REFCURSOR;
l_sql_stmt VARCHAR2(100);
BEGIN
IF( v_action = 'DO THIS' )
THEN
l_sql_stmt := 'SELECT * from ';
ELSE
l_sql_stmt := 'SELECT * from ';
END IF;
OPEN get_records FOR l_sql_stmt;
...