21/10/2013

[PL/SQL] Oracle continue loop with goto

Oracle database versions previous than 11g do not support the CONTINUE statement to skip to the end of a loop and keep cycling. As an alternative, you can use the GOTO statement WITH CAUTION.

Firstly, declare a label which marks the point were you want the execution to continue from using:

 <<label_name>>  

and remember that the label must be followed by an executable statement; in practice, it means you cannot place it directly before the END LOOP instruction. Instead, follow it with a NULL statement as in:

   <<label_name>>  
   NULL;  
 END LOOP;  

Then simply skip to it as needed with:

GOTO label_name;

No comments:

Post a Comment

With great power comes great responsibility.

Da grandi poteri derivano grandi responsabilità.