PL/SQL While Loop

Sharing is Caring

PL/SQL WHILE loop is used to execute statements as long as given condition is true and the condition is checked at the beginning of each iteration, We use PLSQL While loop when we are not sure about that how many times statements should be executed, In while loop condition is evaluated before entering the loop section and terminates when the given condition becomes False or null.

The syntax of PLSQL While loop is like this, First is the condition and next is the set of statements that user wants to execute.

WHILE condition

statements to execute

END LOOP;

Look at this sample code for better understanding

PL/SQL While loop example

DECLARE 
-- Counter variable
i int :=1;
-- Value for table
j int :=5;
BEGIN
-- Check While condition at the start of iteration
WHILE i<11 LOOP
-- Print table of varibale j
dbms_output.put_line(j||'*'||i||'='||i*5);
-- Increment counter
i:=i+1;
END LOOP;
END;

and output is

PL/SQL While Loop

Cheers 🙂 Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

Leave a Reply

Your email address will not be published. Required fields are marked *