The continue statement is used to exit the loop from the reminder if its body either conditionally or unconditionally and forces the next iteration of the loop to take place, skipping any codes in between.
The continue statement is not a keyword in Oracle 10g. It is a new feature encorporated in oracle 11g.
For example: If a continue statement exits a cursor FOR LOOP prematurely then it exits an inner loop and transfer control to the next iteration of an outer loop, the cursor closes (in this context, CONTINUE works like GOTO).
Example of PL/SQL continue statement
Let’s take an example of PL/SQL continue statement.
- x NUMBER := 0;
- LOOP — After CONTINUE statement, control resumes here
- DBMS_OUTPUT.PUT_LINE (‘Inside loop: x = ‘ || TO_CHAR(x));
- x := x + 1;
- IF x < 3 THEN
- END IF;
- (‘Inside loop, after CONTINUE: x = ‘ || TO_CHAR(x));
- EXIT WHEN x = 5;
- END LOOP;
- DBMS_OUTPUT.PUT_LINE (‘ After loop: x = ‘ || TO_CHAR(x));
After the execution of above code, you will get the following result:
Inside loop: x = 0 Inside loop: x = 1 Inside loop: x = 2 Inside loop, after CONTINUE: x = 3 Inside loop: x = 3 Inside loop, after CONTINUE: x = 4 Inside loop: x = 4 Inside loop, after CONTINUE: x = 5 After loop: x = 5