Oracle PL/SQL - PL SQL Statement Nested loops

Introduction

You can create multiple loops nested within each other.

Demo

SQL>
SQL> declare-- w  w  w .  j ava 2s .c  o  m
  2       v_ind_nr     NUMBER;
  3       v_current_nr NUMBER;
  4  begin
  5       v_current_nr:=0; -- should not be null!
  6       loop
  7            v_ind_nr:=0; -- reset each time
  8            loop
  9                 v_ind_nr:=v_ind_nr+1;
 10                 DBMS_OUTPUT.put_line(v_current_nr);
 11                 exit when v_ind_nr=4;
 12            end loop;
 13            v_current_nr:=v_current_nr+5;
 14            exit when v_current_nr=25;
 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

PL/SQL procedure successfully completed.
SQL>

Related Topic