if you try to reference a variable before you declare it because PL/SQL requires an identifier be declared before we use it in our code : Variable Scope « PL SQL « Oracle PL / SQL






if you try to reference a variable before you declare it because PL/SQL requires an identifier be declared before we use it in our code

  
SQL>
SQL>
SQL> declare
  2    myNumber number := another_number;
  3    another_number number := 10;
  4  begin
  5    null;
  6  end;
  7  /
  myNumber number := another_number;
                     *
ERROR at line 2:
ORA-06550: line 2, column 22:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 2, column 12:
PL/SQL: Item ignored


SQL>
SQL>
SQL> declare
  2    another_number number := 10;
  3    myNumber number := another_number;
  4  begin
  5    null;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL>
SQL>

   
  








Related examples in the same category

1.Variable scope in variable 'declare' block
2.Illustrates the scope of various identifiers
3.Variable scope in a PL/SQL
4.Identifiers defined in the declaration of the child block are only in scope and visible within the child block itself.
5.This type is local to this block
6.Reference Type in another block as well
7.variable scope with nested block
8.Override your scope access to containing blocks by reusing an identifier in a nested block