Oracle PL/SQL - Declaring Same Identifier in Different Unit Level

Introduction

You can declare the same identifier in two different units. For example, use the same variable names in two procedures.

The two objects represented by the identifier are distinct.

Changing one does not affect the other.

Demo

SQL>
SQL> DECLARE-- from  www  .j  ava 2s.  c om
  2    PROCEDURE p
  3    IS
  4      x VARCHAR2(1);
  5    BEGIN
  6      x := 'a'; 
  7      DBMS_OUTPUT.PUT_LINE('In procedure p, x = ' || x);
  8    END;
  9
 10    PROCEDURE q
 11    IS
 12      x VARCHAR2(1);
 13    BEGIN
 14      x := 'b'; 
 15      DBMS_OUTPUT.PUT_LINE('In procedure q, x = ' || x);
 16    END;
 17
 18  BEGIN
 19    p;
 20    q;
 21  END;
 22   /
In procedure p, x = a
In procedure q, x = b

PL/SQL procedure successfully completed.

SQL>

Related Topic