Oracle PL/SQL - PL SQL Introduction Blocks


The simplest kind of PL/SQL code is called an anonymous block.

An anonymous block is a block of code that has its own DECLARE/BEGIN/END structure.

Anonymous blocks can either stand on their own or they can sit within any other PL/SQL program.

      <Declaration part>
     <Procedural part> 
     <Exception handler> 


The declaration defines all variables, cursors, subprograms, and other elements to be used.

This section is optional, and you may skip it if no variables or program elements need to be declared.


The procedural section contains the main body of PL/SQL.

It starts with the begin keyword and ends with the exception keyword or the end keyword if you have no exception section.

This part is mandatory.

You must have at least one line of executable code in the procedural section.

If you don't have anything to execute, you can use the NULL command.


The exception section is optional.

It allows the program to intercept and process special conditions that could happen at runtime.

For example, divide by zero, duplicate value of the primary key, and so on.

Related Topic