BEGIN … END
Delimits a block of statements
<block> ::=
BEGIN
[<compound_statement> ...]
END
<compound_statement> ::= {<block> | <statement>}
The BEGIN … END construct is a two-part statement that wraps a block of statements that are executed as one unit of code.Each block starts with the keyword BEGIN and ends with the keyword END.Blocks can be nested a maximum depth of 512 nested blocks.A block can be empty, allowing them to act as stubs, without the need to write dummy statements.
The BEGIN … END itself should not be followed by a statement terminator (semicolon).However, when defining or altering a PSQL module in the isql utility, that application requires that the last END statement be followed by its own terminator character, that was previously switched — using SET TERM — to a string other than a semicolon.That terminator is not part of the PSQL syntax.
The final, or outermost, END statement in a trigger terminates the trigger.What the final END statement does in a stored procedure depends on the type of procedure:
-
In a selectable procedure, the final
ENDstatement returns control to the caller, returning SQLCODE 100, indicating that there are no more rows to retrieve -
In an executable procedure, the final
ENDstatement returns control to the caller, along with the current values of any output parameters defined.