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.
<<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