PL/SQL is a block-structured language. Each of the basic
programming units you write to build your application is (or should be) a
logical unit of work. The PL/SQL block allows you to reflect that logical structure
in the physical design of your programs.
Each PL/SQL block has up to four
different sections (some are optional under certain circumstances):
The block structure is at the core
of two key concepts and features of the PL/SQL language:
Modularization - The PL/SQL block is the basic unit of work from which
modules, such as procedures and functions, are built. The ability to modularize
is central to successfully developing complex applications.
Scope - The block provides a scope or context for logically related
objects. In the block, you group together declarations of variables and
executable statements that belong together.
You can create anonymous blocks
(blocks of code that have no name) and named blocks, which are procedures and
functions. Furthermore, you can build packages in PL/SQL that group together
multiple procedures and functions.
Header - Relevant for named blocks only. The header determines the
way the named block or program must be called.
Declaration section - The part of the block that declares variables, cursors, and
sub-blocks that are referenced in the execution and exception sections.
Execution section - The part of the PL/SQL block containing the executable
statements, the code that is executed by the PL/SQL runtime engine.
Exception section - The section that handles exceptions to normal processing
(warnings and error conditions).
The ordering of the sections in a
block corresponds to the way you would write your programs and the way they are
executed:
Step 1 - Define the type of block (procedure, function, anonymous)
and the way it is called (header).
Step 2 - Declare any variables used in that block (declaration
section).
Step 3 - Use those local variables and other PL/SQL objects to
perform the required actions (execution section).
Step 4 - Handle
any problems that arise during the execution of the block (exception section).
No comments:
Post a Comment