BEGIN

Synopsis

BEGIN
  [ DECLARE ... ]
  statements
END

Description

Marks the start and end of a block in a SQL routine. 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 routine, separated by ;. The following statements can be used:

Examples

The following example computes the value 42:

FUNCTION meaning_of_life()
  RETURNS tinyint
  BEGIN
    DECLARE a tinyint DEFAULT 6;
    DECLARE b tinyint 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 SQL routines examples documentation.

See also

success-mail-img

You've joined our email list. Our newsletter will be delivered to your inbox every other week, with news from Peaka and the no-code world, as well as updates on the latest trends and developments in the data integration space!

success-mail-img

Thank you for your interest. We'll contact you soon.