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;
/