Introduction

A variable is visible only in blocks where you can reference the identifier by using an unqualified name.

A variable is local to the block where it is declared.

A variable is global to all sub-blocks of the block where it is declared.

In the following code, variable V_STR1_tx is local for the block labeled <<MAIN>> and global for the block labeled <<SUB>>.

Variable V_STR2_tx is visible only in the block <<SUB>>.

Demo

SQL>
SQL> <<MAIN>>-- w  w w. j a  v a  2 s.  c om
  2  declare
  3       v_str1_tx VARCHAR2(10);
  4  begin
  5       v_str1_tx :='ABC'; -- local
  6       <<SUB>>
  7       declare
  8            v_str2_tx VARCHAR2(1);
  9       begin
 10            v_str1_tx:='ABC'; -- local
 11            v_str2_tx:='A'; -- global and visible
 12       end;
 13       v_str1_tx :='ABC'; -- local
 14  end;
 15  /

PL/SQL procedure successfully completed.

SQL>

Related Topic