I have a fetch being executed inside of a loop. If this fetch fails (no data) I would like to CONTINUE
the loop to the next record from within the EXCEPTION
.
Is this possible?
I'm getting a ORA-06550
& PLS-00201 identifer CONTINUE must be declared
DECLARE v_attr char(88); CURSOR SELECT_USERS IS SELECT id FROM USER_TABLE WHERE USERTYPE = 'X'; BEGIN FOR user_rec IN SELECT_USERS LOOP BEGIN SELECT attr INTO v_attr FROM ATTRIBUTE_TABLE WHERE user_id = user_rec.id; EXCEPTION WHEN NO_DATA_FOUND THEN -- user does not have attribute, continue loop to next record. CONTINUE; END; END LOOP; END;
By putting a BEGIN-END block with an exception handler inside of a loop, you can continue executing the loop if some loop iterations raise exceptions. You can still handle an exception for a statement, then continue with the next statement.
As you are saying that you are using try catch within a for each scope and you wants to continue your loop even any exception will occur. So if you are still using the try catch within the loop scope it will always run that even exception will occur. it is upto you how you deal with exception in your way.
When a continue statement occurs within a finally block, the target of the continue statement must be within the same finally block. You cannot continue execution of the loop, because an uncaught exception will transfer control to another function, otherwise, a compile-time error occurs.
The CONTINUE
statement is a new feature in 11g.
Here is a related question: 'CONTINUE' keyword in Oracle 10g PL/SQL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With