How to Work With WHILE Loop Statements in PL/SQL

In this article I am going to explain how to work with while loop statements in PL/SQL.
  • 2301

Introduction

PL/SQL is define as procedure language/structure query language.  PL/SQL is developed by oracle. PL/SQL supports many feature like variables, loops, conditions  and exceptions. It also support the concept of array. In present time PL/SQL is integrated component of oracle software. SQL provide limited support for advance programming and PL/SQL fill this gap.

Block is a basic unit of a PL/SQL application. This block is collection of PL/SQL statements grouped as logical unit. Using  PL/SQL blocks you can create five different type of program units.

  • Stored Function
  • Stored procedure
  • Anonymous Block
  • Trigger
  • Package

LOOP statements execute a sequence of statements multiple times. There are three types of LOOP statements

  • LOOP
  • WHILE - LOOP
  • FOR - LOOP

Work with WHILE LOOP Statement

Statements in the loop body are executed in  the WHILE-LOOP statement  as long as a condition is true.

WHILE condition LOOP
statements1;
statements2;
END LOOP;

Example of While Loop Statement

declare
ct NUMBER := 1;
begin
WHILE ct<5 loop
ct := ct+1;
end loop;
END;


© 2020 DotNetHeaven. All rights reserved.