Oracle PL/SQL - FOR LOOP Statement Index with Same Name as Variable

Introduction

If the index of a FOR LOOP statement has the same name as a variable declared in an enclosing block, the local implicit declaration hides the other declaration.

Demo

SQL>
SQL> DECLARE-- from   w  ww .  j a  va  2 s .c  o m
  2    i NUMBER := 5;
  3  BEGIN
  4    FOR i IN 1..3 LOOP
  5      DBMS_OUTPUT.PUT_LINE ('Inside loop, i is ' || TO_CHAR(i));
  6    END LOOP;
  7
  8    DBMS_OUTPUT.PUT_LINE ('Outside loop, i is ' || TO_CHAR(i));
  9  END;
 10  /
Inside loop, i is 1
Inside loop, i is 2
Inside loop, i is 3
Outside loop, i is 5

PL/SQL procedure successfully completed.

SQL>

Related Topic