Each PL/SQL program consists of SQL and PL/SQL stat4plents Which form a PUSQL block. A PUSQL block is shown in figure 4.1. -
A PL/SQL Block consists of following sections:
1 ) Declaration Section: The Declaration section of a
PL/'SQL Block starts with the reserved keyword DECLARE. This section is
optional and is used to declare any placeholders like variables, constants,
records, and cursors, which are used to manipulate data in the execution
section. Placeholders may be any of Variables, Constants, and Records, which
stores data temporarily. Cursors are also declared in this section.
2) Begin Section: It consists of a set of SQL and PL/SQL statements,
which describe processes that have to be applied to table data. Actual data
manipulation. retrieval. looping_ and branching_ constructs are specified in
this section.
3) Execution Section: The Execution section of a PL/SQL
Block Starts with the reserved keyword BEGIN and ends with END. This is a
mandatory section and is the section where the logic is written to perform any
task. The programmatic constructs like loops. conditiona1 statement and SQL
statements form the part of execution section.
4) Exception Section: The Exception section of a PL/SQL
Block starts with the reserved keyword EXCEPTION, This section is
optionai. Any errors in the program can
be handled in this section. so that the PL/SQL Blocks terminate gracefully. If
the PL/SQL Block contains exceptions that cannot be handled. the Block
terminates abruptly with errors.
5) End Section: This marks the end of a PL/SQL. block.
Every statement in the above three sections must end with a
semicolon. PL./SQL blocks can he nested within other PL/SQL blocks Comments be
used to document code.