Syntax of WHILE LOOP in Oracle PL/SQL

Example of WHILE LOOP in Oracle PL/SQL

While loop is used to execute the statements on condition based, it will check first condition then run the body statements. If condition not match then its exit. It may or may not run based on condition specified in WHILE loop.

Syntax:

WHILE <condition>
LOOP
   <statements>
END LOOP;

Example of While loop:
Check while condition first that variable is less than 20 then execute.

SET SERVEROUTPUT ON
DECLARE 
   v_id number(2); 
BEGIN 
   v_id := 1;
   WHILE (v_id <= 20) 
   LOOP 
	dbms_output.put_line('id: ' || v_id); 
	v_id := v_id + 1;
   END LOOP; 
END; 
/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.