PL/SQL Block Structure
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 procedures, functions, or triggers.
In the sections below, we review the structure of a block and focus on the anonymous block. We’ll explore the different kinds of named blocks later in this chapter.
Sections of the block
A PL/SQL block has up to four different sections, only one of which is mandatory. Figure 1-1 illustrates the block structure.

- Header
Used only for named blocks . The header determines the way the named block or program must be called. Optional.
- Declaration section
Identifies variables, cursors, and sub-blocks that are referenced in the execution and exception sections. Optional.
- Execution section
Contains statements that the PL/SQL runtime engine will execute at runtime. Mandatory.
- Exception section
Handles exceptions to normal processing (warnings and error conditions). Optional.
Anonymous blocks
When someone wishes to remain anonymous, that person goes unnamed. The same is true of the anonymous block in PL/SQL, which is shown in Figure 1-2: it lacks a header section ...