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--   ww  w .j  av a 2  s .co 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