Nested Blocks
• What are Nested Blocks?
• Why Use Nested Blocks?
• Rules for Nested Blocks
• Global vs. Local Objects
• Global vs. Local Exceptions
Oracle 11g PL/SQL Fundamentals I
What are Nested Blocks?
As the size and complexity of your
programs increase, a more advanced way
of organizing the code becomes essential.
• A Nested Block is a complete PL/SQL
program block enclosed within the BEGIN
section of another block.
BEGIN
Outer BEGIN Inner
Block …
Block
END;
END;
Oracle 11g PL/SQL Fundamentals I
Why Use Nested Blocks?
• Nested Blocks are helpful in enclosing
SELECT or other statements that may
generate an exception.
• If an Exception occurs, it is handled by the
Inner Block.
• Processing may continue in the Outer Block
• If a Nested Block were not used in this
example, the entire program would exit
by passing control to the EXCEPTION
Clause.
Oracle 11g PL/SQL Fundamentals I
Rules for Nested Blocks
• There are specific rules associated to
Nested Blocks:
• The boundaries of inner and outer blocks are
identified using labels and the END
statement.
• A maximum of 200 Nested Blocks may be
created.
• Nested Blocks may NOT begin within the
DECLARE clause of the enclosing block.
• A Nested Block may only begin within the
BEGIN or EXCEPTION clause of the enclosing
block.
Oracle 11g PL/SQL Fundamentals I
See it in Action
Oracle 11g PL/SQL Fundamentals I