Nesting Blocks

Contact Us or call 1-877-932-8228
Nesting Blocks

Nesting Blocks

The ability to nest blocks in PL/SQL will allow you to better organize your programs. Blocks can be used to prevent variables from being accessed improperly and to allow exceptions to be handled effectively.

Code Sample:

Nested-Blocks/Demos/nested_block.sql
begin

   dbms_output.put_line('In the main block.');

   begin
   
    dbms_output.put_line('In a nested block.');
   
   end;
   
end;

Code Explanation

This is a simple example of how PL/SQL blocks can be nested inside of one another. When the example is run, the two lines of text are printed out in sequence. This shows that when a BEGIN keyword is encountered during normal execution (rather than in the context of a raised error) control will drop to the nested block.

Next