René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

PL/SQL Blocks

A PL/SQL block contains 1 ore more PL/SQL statements. Such a block must at least have the two keywords begin and end:
begin
  sql statements
end;

declare

However, such a block cannot declare any (local) variables. In order to have local variables, the begin...end block must be preceeded with a declare followed by the variable declarations:
declare
  variable declarations
begin
  sql statements
end;

Exceptions

Additinonally, it is possible to have a exception handler as part of the block. The exception keyword is required for this:
declare
  variable declarations
begin
  sql statements
exception
  exception handler
end;
<<name-for-block>>
declare
  variable declarations
begin
  sql statements
end;
A block can be named. Such a label can then be the target of a goto and exit statement.
<<name-for-block>>
declare
  variable declarations
begin
  sql statements
end name-for-block;
A block can be (recursively) nested, that is, a block can contain other blocks, which in turn can again contain other blocks asf.
declare
  variable declarations
begin
  sql statements

  declare
    variable declarations
  begin
    sql statements
  exception
    exception handler
  end;

  further-sql-statements

exception
  exception handler
end;