Introduction

A WHILE loop is equivalent to a regular loop with an EXIT WHEN as the first statement.

The syntax is shown as follows.

while <<condition>> 
 loop  
     ...<<set of statements>>... 
end loop; 

Nested WHILE Loop

Demo

SQL>
SQL> declare-- www  . ja v  a  2  s. co  m
  2        v_ind_nr     NUMBER;
  3        v_current_nr NUMBER;
  4  begin
  5        v_current_nr:=0; -- should not be null!
  6        while v_current_nr <= 25
  7        loop
  8             v_ind_nr:=0; -- reset each time
  9             while v_ind_nr<4
 10             loop
 11                   v_ind_nr:=v_ind_nr+1;
 12                   DBMS_OUTPUT.put_line(v_current_nr);
 13             end loop;
 14             v_current_nr:=v_current_nr+5;
 15        end loop;
 16  end;
 17  /
0
0
0
0
5
5
5
5
10
10
10
10
15
15
15
15
20
20
20
20
25
25
25
25

PL/SQL procedure successfully completed.
SQL>

Related Topic