switch between two cursors based on parameter passed into stored procedure
- by db83
Hi,
I have two cursors in my procedure that only differ on the table name that they join to.
The cursor that is used is determined by a parameter passed into the procedure
if (param = 'A') then
DECLARE CURSOR myCursor IS
SELECT x,y,z
FROM table1 a, table2 b
BEGIN
FOR aRecord in myCursor
LOOP
proc2(aRecord.x, aRecord.y, aRecord.z);
END LOOP;
COMMIT;
END;
elsif (param = 'B') then
DECLARE CURSOR myCursor IS
SELECT x,y,z
FROM table1 a, table3 b -- different table
BEGIN
FOR aRecord in myCursor
LOOP
proc2(aRecord.x, aRecord.y, aRecord.z);
END LOOP;
COMMIT;
END;
end if
I don't want to repeat the code for the sake of one different table.
Any suggestions on how to improve this?
Thanks in advance