In PL/SQL, as in most other procedural languages, the smallest meaningful grouping of code is known as a block. A block is a unit of code that provides execution and scoping boundaries for variable declarations and exception handling. PL/SQL allows you to create anonymous blocks (blocks of code that have no name) and named blocks, which may be packages, procedures, functions, triggers, or object types.
A PL/SQL block has up to four different sections, only one of which is mandatory:
Used only for named blocks. The header determines the way the named block or program must be called. Optional.
Identifies variables, cursors, and subblocks that are referenced in the execution and exception sections. Optional.
Statements the PL/SQL runtime engine will execute at runtime. Mandatory.
Handles exceptions to normal processing (warnings and error conditions). Optional.
Figure 3-1 shows the structure of the PL/SQL block for a procedure.
Figure 3-1. The PL/SQL block structure
Figure 3-2 shows a procedure containing all four sections of the elements of a block. This particular block begins with the keyword PROCEDURE, and, like all blocks, ends with the keyword END.
Figure 3-2. A procedure containing all four sections