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 packages, procedures, functions, triggers, or object types.
A PL/SQL block has up to four different sections, only one of which is mandatory:
- 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 subblocks that are referenced in the execution and exception sections. Optional.
- Execution section
Statements the PL/SQL runtime engine will execute at runtime. Mandatory.
- Exception section
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
Anonymous ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access