Continue Statement in Pl Sql Example

This is an excerpt from the book PL/SQL: The Definitive Reference by Boobal Ganesan.

The Continue statement exits the current iteration of the loop unconditionally and then transfers the control to the next iteration of the current loop.

Continue;

In the below example, the Continue statement exits the current iteration of the FOR loop and transfers the control to the next iteration without executing the statement present after it.

1. BEGIN

2. FOR loop_index IN 1..5

3. LOOP

4. dbms_output.put_line(loop_index);

5. dbms_output.put_line('Before the Continue statement');

6. CONTINUE;

7. dbms_output.put_line('After the Continue statement');

8. END LOOP loop_index;

9. dbms_output.put_line('Loop has been terminated');

10. END;

11. /

Result:

1

Before the Continue statement

2

Before the Continue statement

3

Before the Continue statement

4

Before the Continue statement

5

Before the Continue statement

Loop has been terminated

Script Explanation

Line no.

Description

1

Start of the execution section of the block.

2,3

Start of the FOR loop with the lower bound value as 1 and the upper bound value as 5.

4

The loop index's value is printed for every iteration using the DBMS_OUTPUT.PUT_LINE procedure.

5

The start of the continue statement is indicated using the DBMS_OUTPUT.PUT_LINE procedure.

6

The continue statement is placed.

7

The end of the continue statement is indicated using the DBMS_OUTPUT.PUT_LINE procedure.

8

End of the FOR loop.

9

The loop's termination is indicated using the DBMS_OUTPUT.PUT_LINE procedure.

10,11

End of the execution section.

CONTINUE WHEN Statement

The Continue-When statement exits the current iteration of the loop when the condition in it's WHEN clause is satisfied and then transfers the control to the next iteration of the current loop.

Continue when <condition>;

Whenever the control reaches the Continue-When statement during the loop iteration, it's WHEN condition is evaluated. If the evaluation is satisfied, the control is transferred to the next iteration of the current loop, if not satisfied, the statement does nothing and the loop stays alive and proceeds executing the statements present for the current iteration.

In the below example, the Continue-When statement exits the current iteration of the FOR loop once it's WHEN condition is satisfied, in this case when the loop index turns 3, the condition is satisfied and then transfers the control to the next iteration without executing the statement present after it.

1. BEGIN

2. FOR loop_index IN 1..5

3. LOOP

4. CONTINUE

5. WHEN loop_index=3;

6. dbms_output.put_line(loop_index);

7. END LOOP loop_index;

8. dbms_output.put_line('Loop has been terminated');

9. END;

10. /

Script Explanation

Line no.

Description

1

Start of the execution section of the block.

2,3

Start of the FOR loop with the lower bound value as 1 and the upper bound value as 5.

4,5

The continue statement is placed with the condition loop_index=3.

6

The loop index's value is printed for every iteration using the DBMS_OUTPUT.PUT_LINE procedure.

7

End of the FOR loop.

8

The loop's termination is indicated using the DBMS_OUTPUT.PUT_LINE procedure.

9,10

End of the execution section.

Oracle Training from Don Burleson

The best on site " Oracle training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

Oracle training


Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata? Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just e-mail:

and include the URL for the page.


Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

conleywhasuff.blogspot.com

Source: http://www.dba-oracle.com/t_adv_plsql_continue.htm

Related Posts

0 Response to "Continue Statement in Pl Sql Example"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel