PL/SQL Exception

PL/SQL Exception

PL/SQL Interview Questions

PL/SQL Interview Questions and Answers


PL/SQL While Loop Statement

The PL/SQL WHILE LOOP statement will execute a block of code when a given condition is true. If the condition evaluates to TRUE, the block of code is executed, if condition evaluates to FALSE, the loop terminates and control is passed to the next executable statement following the END LOOP keywords.

Use PL/SQL WHILE LOOP when you don't know how many times the loop will execute. If you know in advanced number of time iterations, use the PL/SQL FOR LOOP statement instead.

PL/SQL While Loop Statement Syntax

To execute a block of code when a given condition is true, use the following syntax:

Syntax

PL/SQL While 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:

  • First, we initialize the counter to 1.
  • Second, in each iteration, we increasing counter with 1.
  • Third, we display the result of the counter.
  • Fourth, The loop is terminated when the counter reaches to 10.