Tell Me
 

PL/SQL Blocks

Previous previous|next Next Page

The basic construct in PL/SQL is a block. A block consists of a set of SQL and/or PL/SQL statements, joined together and passed to the Oracle engine all in one go.

  • Declarative(optional): This section begins with the keyword DECLARE and ends when your executable section starts.
  • Executable(required): This section begins with the keyword BEGIN and ends with END. The keyword END should be terminated with a semicolon.
  • Exception handling(optional): The exception section is nested within the executable section. This section begins with the keyword EXCEPTION.

A PL/SQL program is comprised of one or more blocks. These blocks can be entirely separate or nested within another.

There are three types of blocks that make up a PL/SQL program:

  • Anonymous blocks: These are the unnamed PL/SQL blocks that are embedded within an application or are issued interactively.
  • Procedures: These are the named PL/SQL blocks. These blocks accept inbound parameters but won't explicitly return any value.
  • Functions: These are the named PL/SQL blocks. These blocks accept inbound parameters and will always return a value.

The difference between a procedure and a function is that a function must return a value to the calling program.