Skip to main content

BEGIN

Synopsis

BEGIN
[ DECLARE ... ]
statements
END

Description

Marks the start and end of a block in a SQL user-defined functions. BEGIN can be used wherever a statement can be used to group multiple statements together and to declare variables local to the block. A typical use case is as first statement within a FUNCTION. Blocks can also be nested.

After the BEGIN keyword, you can add variable declarations using DECLARE statements, followed by one or more statements that define the main body of the SQL UDF, separated by ;. The following statements can be used:

Examples

The following example computes the value 42:

FUNCTION meaning_of_life()
RETURNS integer
BEGIN
DECLARE a integer DEFAULT 6;
DECLARE b integer DEFAULT 7;
RETURN a * b;
END

Further examples of varying complexity that cover usage of the BEGIN statement in combination with other statements are available in the Example SQL UDFs.

See also