PL/SQL Exception

PL/SQL Exception

PL/SQL Interview Questions

PL/SQL Interview Questions and Answers


PL/SQL For Loop Statement

The PL/SQL FOR LOOP control statement will execute a block of code, when you already know how many number of times should perform or you want loop through a block of code to specific number of time.

Unlike the PL/SQL WHILE LOOP, the number of iterations of the PL/SQL FOR LOOP is known before the loop starts. The loop is iterated between the start and end integer values.

PL/SQL For Loop Statement Syntax

To execute a block of code, when you already know how many number of times should perform or you want loop through a block of code to specific number of time., use the following syntax:

Syntax

PL/SQL For Loop Statement example

The following PL/SQL uses to execute a block of code when a given condition is true:

Example

Let's understand how it works:

  • Here, you don't need to declare the counter variable.
  • Second, in each iteration, counter variable increased by 1 implicitly.
  • Third, we display the result of the counter.
  • Fourth, loop is terminated when the counter reaches to 100.
  • Fifth, you can use EXIT WHEN statements and EXIT statements in FOR Loops.