Variable scope in different program block : Program Block « PL SQL « Oracle PL / SQL






Variable scope in different program block


SQL>
SQL>
SQL> -- variable scope
SQL>
SQL>  declare
  2      parent_number number;
  3    begin
  4      -- parent_number is visible and in scope
  5      parent_number := 1;
  6
  7      declare
  8        child_number number := 2;
  9      begin
 10        -- child_number is visible
 11        dbms_output.put_line('parent + child = ' ||
 12                              to_char(parent_number + child_number));
 13      end;
 14
 15      -- child_number is now not visible nor in scope:
 16      child_number := 2;
 17      dbms_output.put_line(child_number);
 18
 19    end;
 20    /
    child_number := 2;
    *
ERROR at line 16:
ORA-06550: line 16, column 5:
PLS-00201: identifier 'CHILD_NUMBER' must be declared
ORA-06550: line 16, column 5:
PL/SQL: Statement ignored
ORA-06550: line 17, column 26:
PLS-00201: identifier 'CHILD_NUMBER' must be declared
ORA-06550: line 17, column 5:
PL/SQL: Statement ignored


SQL>
SQL>
SQL>
           
       








Related examples in the same category

1.PL SQL block for start
2.Anonymous block with error handling
3.Basic PL/SQL program block