Search notes:

PL/SQL Blocks

A PL/SQL block is a fundamental construct in PL/SQL: among others, they're used
A block consists of:
label optional
declare section optional Used to declare variables, constants, types etc. that are used in this block und embeded sub blocks. These declared items are not available in enclosing blocks.
body required the executable part of the block contains a series of PL/SQL statements.
exception handler optional technically part of the body: where execution is transferred to when an error occurs.
Blocks can be nested: a block's body (and exception handler because they're part of the body) can contain any number of nested sub-blocks.
A nested block cannot have a pragma autonomous_transaction.
<<tq84>>                             -- This block has the (optional) label TQ84
                                     --
declare                              -- The declare section. Here, it
   v1 number;                        --     declares the variable v1
                                     --
begin                                -- Start of the body.
   v1 := 7/3;                        --    The body contains the statements to
   dbms_output.put_line(v1);         --    be executed.
                                     --
exception                            -- Exception hander: used to
   when others then                  --    manage errors.
     dbms_output.put_line(sqlerrm);  --    The exception handler consists of
     raise;                          --    statements as well.
end;                                 -- End of the block.  

Exception handler

After the exception handler is finished with execution, the next statement that is executed is the statement that follows the exception handler in its enclosing block.
If there is no enclosing block, execution is transferred to the invoker or the host environment.

SQLERRM and SQLCODE

Two noteworthy functions to be used in the exception handler are
Outside of an exception handler, these function return 0 and ORA-00000, respectively. In SQL statements, sqlerrm and sqlcode are not recognized.

Index