RETURN BOOLEAN IS
CURSOR c_au IS
SELECT user_id FROM all_users;
BEGIN
FOR v_au_rec IN c_au LOOP
IF c_au%ISOPEN THEN
CLOSE c_au;
END IF;
RETURN TRUE;
END LOOP;
RETURN FALSE;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
But I thought this should still work without an error but it doesn't.
Running this gives the ORA-010001: invalid cursor error but now where I expected.
It is actually raised as part of the RETURN TRUE;
I assume it is because the cursor is already closed by the explicit CLOSE statement so when it does the implicit close as part of the RETURN FALSE from the loop it fails as the cursor is already gone.
The simple solution is to let Oracle handle the close itself and remove the code to check and close the cursor.
No comments:
Post a Comment