Tuesday, 22 May 2012

In the following code snippet, can the v_ex variable reference the value of the key variable? | PL SQL

Declare
v_ex number;
Begin
...
Declare
v_ey number;
Begin
v_ey := v_ex;
End;
....
End;

 In the given code snippet, the v_ey variable can refer to the value of the v_ex variable, but the v_ex variable cannot refer the value of the v_ey variable. This is because; the scope of the variable in a nested block is limited to the variables that are declared in the blocks, which are above the block it is declared in, and not the blocks below that particular block.
   In other words, a block can look up to the enclosing blocks but cannot look down to the enclosed blocks. This is defined as  a scope of an identifier. Therefore, an identifier is local to the block it is declared in and global to its sub-blocks.