PL SQL Syntax


 

Basic Syntax

The basic PL/SQL block consists of mainly three sections: declaration, executable and exception handling. The execution section is mandatory but the declaration and exception handling are optional. 
The sample PL/SQL block looks as follows:


DECLARE
 <declaration section>

BEGIN
 <executable section>

EXCEPTION
 <exception section>

END;

 

Explanation


Declaration section


It always starts with the DECLARE keyword. Here variables, subprograms, cursors, and other elements used in the program are defined. It is optional.


Executable section


It is mandatory which falls between the begin and end keywords. It must contain at least a line of code and here all executable PL/SQL statements are written. Also, the NULL command can be used if there is nothing for it to do at the time.


Exception


It is optional and it is used to handle error(s) that may occur in the program.