Friday, February 24, 2012

Block structure and Advantages of PL/SQL

PL/SQL is a language focused on blocks, with procedural and processing characteristics of error handling. These blocks are composed of procedures, functions, and anonymous blocks which are grouped together in logical point of view.

    In block there are three basic parts which are declaration, execution, and exception handling. Only execution part is required and the others are optional.

  • Declaration - all block objects must be declared [optional]

  • Execution – the objects are defined for the data processing

  • Exceptions – here are located the error handling routines [optional]

Variable declaration;
Program Execution;
Exception handling;

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.

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 program logic is written to perform any task. The programmatic constructs like loops, conditional statement and SQL statements form the part of execution section.

Exception Section:
The Exception section of a PL/SQL Block starts with the reserved keyword EXCEPTION. This section is optional. Any errors in the program can be handled in this section, so that the PL/SQL Blocks terminates gracefully. If the PL/SQL Block contains exceptions that cannot be handled, the Block terminates abruptly with errors.

Advantages of PL/SQL

  • Integration with Oracle Server

  • Supports the basic SQL commands

  • Defining and managing blocks of instructions

  • Management of variables, constants and cursors

  • Allow implementation and use of triggers

  • PL SQL consists of blocks of code, which can be nested within each other.

  • PL SQL engine processes multiple SQL statements simultaneously as a single block

  • It also reduces the network traffic.

  • Detection and management execution errors, exceptions

No comments:

Post a Comment