PL/SQL allows the nesting of a Block within a
Block i.e., the Execution section of an outer block can contain inner blocks.
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 an inner block and cannot be referenced by outside Blocks.
- Global variables - These are declared in outer block and can be referenced by itself and by its inner blocks.
Now we are creating two variables in the
outer block and assigning their product to the third variable created in the
inner block. Variable 'var_mult' is in the inner block, so cannot be accessed
in the outer block. The variables 'var_num1' and 'var_num2' can be accessed
anywhere in the block.
DECLARE
var_num1 number;
var_num2 number;
BEGIN
var_num1 := 100;
var_num2 := 200;
DECLARE
var_mult number;
BEGIN
var_mult := var_num1 * var_num2;
END;
END;
No comments:
Post a Comment