I have a procedure in Oracle that takes a varchar2 parameter. Based on the value of this parameter, I need to define a cursor. The cursor will work in different tables based on the value of the parameter.
I wanted to do something like below, but this throws an error in the fragment of the CURSOR definition. Any ideas?
PROCEDURE GET_RECORDS(v_action IN VARCHAR2) IS CURSOR get_records IS IF(v_action = 'DO THIS') THEN SELECT * from <THIS>; ELSE SELECT * from <THAT>; END IF; BEGIN OPEN get_records; FETCH get_records INTO v_thing; v_loop := 0; WHILE get_records%FOUND LOOP FETCH get_records INTO v_thing; END LOOP; CLOSE get_records; END;
oracle plsql conditional cursor
Miketwebb
source share