Translate

CONTINUE

What is CONTINUE and CONTINUE WHEN Statement in ORACLE?
The CONTINUE statement exits the current iteration of a loop, either conditionally or unconditionally, and transfers control to the next iteration of either the current loop or an enclosing labelled loop.
The CONTINUE statement causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. In other words, it forces the next iteration of the loop to take place, skipping any code in between.

Syntax:

The syntax for a CONTINUE statement is as follows:
CONTINUE;

This statement comes in two forms, just like EXIT: the unconditional CONTINUE and the conditional CONTINUE WHEN.
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
  2  V_counter NUMBER:=0;
  3  BEGIN
  4  LOOP
  5  V_counter:=V_counter+1;
  6  DBMS_OUTPUT.PUT_LINE('Before CONTINUE Condition, V_counter Value :'||V_counter);
  7  IF V_counter<=3 Then
  8  CONTINUE;
  9  END IF;
 10  DBMS_OUTPUT.PUT_LINE('After CONTINUE Condition, V_counter Value :'||V_counter);
 11  IF V_counter=6 THEN
 12  EXIT;
 13  END IF;
 14  END LOOP;
 15  END;
 16  /
Before CONTINUE Condition, V_counter Value :1
Before CONTINUE Condition, V_counter Value :2
Before CONTINUE Condition, V_counter Value :3
Before CONTINUE Condition, V_counter Value :4
After CONTINUE Condition, V_counter Value  :4
Before CONTINUE Condition, V_counter Value :5
After CONTINUE Condition, V_counter Value  :5
Before CONTINUE Condition, V_counter Value :6
After CONTINUE Condition, V_counter Value  :6

PL/SQL procedure successfully completed.

EXAMPLE OF CONTINUE WHEN
SQL> DECLARE
  2  V_counter NUMBER:=0;
  3  BEGIN
  4  LOOP
  5  V_counter:=V_counter+1;
  6  IF V_counter=6 Then
  7  EXIT;
  8  END IF;
  9  DBMS_OUTPUT.PUT_LINE('Before CONTINUE Condition, V_counter Value :'||V_counter);
 10  CONTINUE WHEN V_counter>3;
 11  DBMS_OUTPUT.PUT_LINE('After CONTINUE Condition, V_counter Value :'||V_counter);
 12  END LOOP;
 13  END;
 14  /
Before CONTINUE Condition, V_counter Value :1
After CONTINUE Condition, V_counter Value  :1
Before CONTINUE Condition, V_counter Value :2
After CONTINUE Condition, V_counter Value  :2
Before CONTINUE Condition, V_counter Value :3
After CONTINUE Condition, V_counter Value  :3
Before CONTINUE Condition, V_counter Value :4
Before CONTINUE Condition, V_counter Value :5

PL/SQL procedure successfully completed.


Get involved and leave your Comments in the Box Below. The more people get involved, the more we all benefit. So, leave your thoughts before you leave the page. 

3 comments:

  1. Thank you for this wonderful resource and all the work put into it.
    How can I setup myself as home user with Windows laptop to practice Oracle/SQL/PL/SQL?
    Many thanks

    ReplyDelete
  2. Welcome to Seekware, your trusted partner for cutting-edge blockchain and AI software development solutions. Our expert team combines the power of blockchain technology with artificial intelligence to create innovative and secure software applications that drive business growth. Whether you need smart contracts, decentralized applications, or AI-powered solutions, we have the expertise to turn your ideas into reality. Explore our services and experience the future of technology with Seekware.

    ReplyDelete