We are having following statements:-
1) CONTINUE
2) CONTINUE WHEN
1) CONTINUE:-
The CONTINUE statement makes to skip the Current iteration of the loop UNCONDITIONALLY and then transfers to next iteration of the current loop.
Syntax: continue;
Eg:
SQL> SET SERVEROUTPUT ON
SQL>
SQL> BEGIN
2 FOR VENKY_IDX IN 1 .. 3 LOOP
3 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX BEFORE ' || VENKY_IDX);
4 CONTINUE;
5 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX AFTER ' || VENKY_IDX);
6 END LOOP VENKY_IDX;
7 DBMS_OUTPUT.PUT_LINE('AFTER LOOP');
8 END;
9 /
VENKY_IDX BEFORE 1
VENKY_IDX BEFORE 2
VENKY_IDX BEFORE 3
AFTER LOOP
PL/SQL procedure successfully completed
2) CONTINUE WHEN:-
Its same as 'CONTINUE' statement but here we can specify any condition to meet that criteria to skip the current iteration and transfer it to next iteration of the current loop.
Syntax: continue when;
Eg:
SQL> BEGIN
2 FOR VENKY_IDX IN 1 .. 3 LOOP
3 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX BEFORE ' || VENKY_IDX);
4 CONTINUE
5 WHEN VENKY_IDX =2;
6 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX AFTER ' || VENKY_IDX);
7 END LOOP VENKY_IDX;
8 DBMS_OUTPUT.PUT_LINE('AFTER LOOP');
9 END;
10 /
VENKY_IDX BEFORE 1
VENKY_IDX AFTER 1
VENKY_IDX BEFORE 2
VENKY_IDX BEFORE 3
VENKY_IDX AFTER 3
AFTER LOOP
PL/SQL procedure successfully completed
In above example when venky_idx becomes 2 then its skipping to execute "DBMS_OUTPUT.PUT_LINE(' VENKY_IDX AFTER ' || VENKY_IDX);" .
Basically Continue when statement will be used to skip some execution if any requirement meets or doesn't meet as above eg.
Flow of Continue statement:-
1) CONTINUE
2) CONTINUE WHEN
1) CONTINUE:-
The CONTINUE statement makes to skip the Current iteration of the loop UNCONDITIONALLY and then transfers to next iteration of the current loop.
Syntax: continue;
Eg:
SQL> SET SERVEROUTPUT ON
SQL>
SQL> BEGIN
2 FOR VENKY_IDX IN 1 .. 3 LOOP
3 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX BEFORE ' || VENKY_IDX);
4 CONTINUE;
5 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX AFTER ' || VENKY_IDX);
6 END LOOP VENKY_IDX;
7 DBMS_OUTPUT.PUT_LINE('AFTER LOOP');
8 END;
9 /
VENKY_IDX BEFORE 1
VENKY_IDX BEFORE 2
VENKY_IDX BEFORE 3
AFTER LOOP
PL/SQL procedure successfully completed
2) CONTINUE WHEN:-
Its same as 'CONTINUE' statement but here we can specify any condition to meet that criteria to skip the current iteration and transfer it to next iteration of the current loop.
Syntax: continue when;
Eg:
SQL> BEGIN
2 FOR VENKY_IDX IN 1 .. 3 LOOP
3 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX BEFORE ' || VENKY_IDX);
4 CONTINUE
5 WHEN VENKY_IDX =2;
6 DBMS_OUTPUT.PUT_LINE(' VENKY_IDX AFTER ' || VENKY_IDX);
7 END LOOP VENKY_IDX;
8 DBMS_OUTPUT.PUT_LINE('AFTER LOOP');
9 END;
10 /
VENKY_IDX BEFORE 1
VENKY_IDX AFTER 1
VENKY_IDX BEFORE 2
VENKY_IDX BEFORE 3
VENKY_IDX AFTER 3
AFTER LOOP
PL/SQL procedure successfully completed
In above example when venky_idx becomes 2 then its skipping to execute "DBMS_OUTPUT.PUT_LINE(' VENKY_IDX AFTER ' || VENKY_IDX);" .
Basically Continue when statement will be used to skip some execution if any requirement meets or doesn't meet as above eg.
Flow of Continue statement:-
Restrictions on CONTINUE Statement:-
- A
CONTINUE
statement must be inside aLOOP
statement.
No comments:
Post a Comment