CONTINUE Statement

In PL/SQL (Procedural Language/Structured Query Language), the CONTINUE statement is used within loops to skip the remaining statements within the loop for the current iteration and move on to the next iteration. The CONTINUE statement is commonly used in combination with conditional statements to control the flow of execution in loops.

Syntax:

CONTINUE;

Example:

DECLARE
   i NUMBER := 1;
BEGIN
   LOOP
      IF i = 3 THEN
         -- Skip the rest of the loop for i = 3
         i := i + 1;
         CONTINUE;
      END IF;

      -- Process other statements inside the loop
      DBMS_OUTPUT.PUT_LINE('Current Value of i: ' || i);

      i := i + 1;

      EXIT WHEN i > 5; -- Exit the loop when i exceeds 5
   END LOOP;
END;
/

When the above code is executed in SQL prompt, it produces the following output.

Output:

Current Value of i: 1
Current Value of i: 2
Current Value of i: 4
Current Value of i: 5

PL/SQL CONTINUE Statement

PL/SQL is a block-structured language that enables developers to combine the power of SQL with procedural statements. All the statements of a block are passed to the Oracle engine all at once which increases processing speed and decreases the traffic.

Similar Reads

CONTINUE Statement

In PL/SQL (Procedural Language/Structured Query Language), the CONTINUE statement is used within loops to skip the remaining statements within the loop for the current iteration and move on to the next iteration. The CONTINUE statement is commonly used in combination with conditional statements to control the flow of execution in loops....

CONTINUE WHEN Statement

In PL/SQL, there isn’t a direct “CONTINUE WHEN” statement, but you can achieve similar functionality using conditional logic with IF statements. Here are multiple examples demonstrating how you can use conditional logic to control the flow within loops in PL/SQL....

Advantages of PL/SQL CONTINUE Statement

Provides a way to skip some specific iterations. Useful to skip the necessary processing in the loop. The nesting levels can be reduced as we may want to skip the rest of the loops. We can selectively skip certain iterations based on specific conditions....

Conclusion

CONTINUE statement terminates the current iteration of a loop within a PL/SQL code block, and moves to the next iteration of the loop. This statement can be embedded within a FOR LOOP , or WHILE statement, or a PL/SQL procedure, function.It provides a way to efficiently manage loop iterations by bypassing unnecessary code execution based on certain conditions....

Contact Us