Oracle PL/SQL - Nested FOR LOOP Statements with Same Index Name

Introduction

The label of the outer loop. For clarity only, the inner loop also qualifies the reference to its own index with its own label.

Demo

SQL>
SQL> BEGIN-- w w w  .  j a  va  2  s  . com
  2    <<outer_loop>>
  3    FOR i IN 1..3 LOOP
  4      <<inner_loop>>
  5      FOR i IN 1..3 LOOP
  6        IF outer_loop.i = 2 THEN
  7          DBMS_OUTPUT.PUT_LINE
  8            ('outer: ' || TO_CHAR(outer_loop.i) || ' inner: '
  9             || TO_CHAR(inner_loop.i));
 10        END IF;
 11      END LOOP inner_loop;
 12    END LOOP outer_loop;
 13  END;
 14  /
outer: 2 inner: 1
outer: 2 inner: 2
outer: 2 inner: 3

PL/SQL procedure successfully completed.

SQL>
SQL>

Related Topic