Scope of variables

Scope of Variables
Nesting of Blocks within Blocks allowed in the PL/SQL. Therefore, a variable which is accessible to an outer Block is also accessible to all nested inner Blocks. The variables declared in the inner blocks are not accessible to outer blocks. Based on their declaration we can classify variables into two types.

  • Local variables - These are declared in a inner block and cannot be referenced by outside Blocks.
  • Global variables - These are declared in a outer block and can be referenced by its itself and by its inner blocks.

For Example: In the below example the variable 'num3' is declared in the inner block, so cannot be accessed in the outer block i.e. it cannot be accessed after line 11. The variables 'num1' and 'num2' can be accessed anywhere in the block.

2> num1 number;
3> num2 number;
5> num1 := 100;
6> num2 := 200;
8> num3 number;
10> num3 := num1 * num2;
11> END;
12> END;
13> /

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License