Block Structure approach

0
Block Structure approach:
  • The basic units that make up a PL/SQL program are logical blocks.
  • The block in PL/SQL can be nested with one another.
  • A block groups related declarations and statements into one single unit.
The basic parts of a PL/SQL block are:
  1. Declarative part (optional).
  2. Executable part (Mandatory).
  3. Exception handling (Optional).

1.Declarative part:It is used to define user defined types, variables which can be used, in the executable part for further manipulations. 

2.Executable part:
All  procedural statements are included between the BEGIN and END statement.
It must have one executable statement.


3.Exception Handling part:
Error that occur during execution are dealt in the exception handling part.

Notes:

  • A PL/SQL program is a logical block, which contain any number of nested sub blocks.
  • Block can be nested in the executable and exception handling parts of a PL/SQL block, or a sub program.
  • A PL/SQL is marked with either a "DECLARE" or "BEGIN" keyword and ends with the keyword "END".
  • Only BEGIN and END keywords are mandatory.
  • A semicolon(;) has to be placed after the "END" keyword.

Block syntax:
SQL> DECLARE
    [Variable declarations;
    Cursor declaration;
    User_defined exception;]
          BEGIN
          <SQL statements;>
          PL/SQL statement
          EXCEPTION
          Action to perform when errors occurs.
          END;
  • Only executable section is required.
  • The declarative and exception handling section are optional.
  • We can define local sub programs in the declarative part of any block.
  • However, we can call local subprograms only from the block in which they are define.
 Click here to go to Back page

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts