Variable visibility : Variable Scope « PL SQL Data Types « Oracle PL/SQL Tutorial






SQL>
SQL> SET SERVEROUTPUT ON
SQL>
SQL> DECLARE
  2     v_visible VARCHAR2(30);
  3     v_hidden VARCHAR2(30);
  4  BEGIN
  5     v_visible := 'v_visible in the outer block';
  6     v_hidden := 'v_hidden in the outer block';
  7
  8     DBMS_OUTPUT.PUT_LINE('*** OUTER BLOCK ***');
  9     DBMS_OUTPUT.PUT_LINE(v_visible);
 10     DBMS_OUTPUT.PUT_LINE(v_hidden);
 11     DBMS_OUTPUT.PUT_LINE('     ');
 12
 13     DECLARE
 14        v_hidden NUMBER(10);
 15     BEGIN
 16        DBMS_OUTPUT.PUT_LINE('*** INNER BLOCK ***');
 17        v_hidden := 'v_hidden in the inner block';
 18        DBMS_OUTPUT.PUT_LINE(v_hidden);
 19     EXCEPTION
 20        WHEN OTHERS
 21        THEN
 22           DBMS_OUTPUT.PUT_LINE('v_hidden of type VARCHAR2 was...hidden');
 23     END;
 24  END;
 25  /
*** OUTER BLOCK ***
v_visible in the outer block
v_hidden in the outer block
*** INNER BLOCK ***
v_hidden of type VARCHAR2 was...hidden

PL/SQL procedure successfully completed.

SQL>








21.37.Variable Scope
21.37.1.Variable visibility
21.37.2.Variable scope
21.37.3.The scope test script