How to Work With LOOP Statements in PL/SQL

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

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 LOOP Statement

The basic loop is the simplest form of LOOP statement in PL/SQL.

LOOP
statements1;
statements2;
statements3;
END LOOP;

Example of While Loop Statement 

DECLARE
x positive :=1;
max_value CONSTANT positive := 10;
begin
loop
x := x+1;
EXIT WHEN x>max_value;
END LOOP;
END;


© 2020 DotNetHeaven. All rights reserved.