Oracle PL/SQL - PL SQL Statement CONTINUE Statement

Introduction

The CONTINUE statement exits the current loop iteration and transfers control to the next iteration of either the current loop or an enclosing labeled loop.

In the following code, the CONTINUE statement inside the basic LOOP statement transfers control to the next iteration of the current loop.

Demo

SQL>
SQL> DECLARE-- from  w w  w  .  ja va2  s.  c  o m
  2     x NUMBER := 0;
  3  BEGIN
  4   LOOP -- After CONTINUE statement, control resumes here
  5     DBMS_OUTPUT.PUT_LINE ('Inside loop:  x = ' || TO_CHAR(x));
  6     x := x + 1;
  7     IF x < 3 THEN
  8       CONTINUE;
  9     END IF;
 10     DBMS_OUTPUT.PUT_LINE('Inside loop, after CONTINUE:  x = ' || TO_CHAR(x));
 11     EXIT WHEN x = 5;
 12   END LOOP;
 13    DBMS_OUTPUT.PUT_LINE (' After loop:  x = ' || TO_CHAR(x));
 14  END;
 15  /
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

PL/SQL procedure successfully completed.

SQL>

Related Topics