Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to CONTINUE a loop from an exception?

Tags:

oracle

plsql

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; 
like image 316
ProfessionalAmateur Avatar asked May 05 '11 19:05

ProfessionalAmateur


People also ask

How do you continue a loop even after an exception?

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.

How do you continue a loop after catching exception in try catch?

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.

Can we use continue in exception?

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.


1 Answers

The CONTINUE statement is a new feature in 11g.

Here is a related question: 'CONTINUE' keyword in Oracle 10g PL/SQL

like image 63
angus Avatar answered Sep 18 '22 15:09

angus