> ## Documentation Index
> Fetch the complete documentation index at: https://docs.peaka.com/llms.txt
> Use this file to discover all available pages before exploring further.

# BEGIN

## Synopsis

```text theme={null}
BEGIN
  [ DECLARE ... ]
  statements
END
```

## Description

Marks the start and end of a block in a [SQL routine](/sql/routines/introduction).
`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](/sql/routines/function). Blocks can also be
nested.

After the `BEGIN` keyword, you can add variable declarations using
[declare](/sql/routines/declare) statements, followed by one or more statements that define
the main body of the routine, separated by `;`. The following statements can be
used:

* [case](/sql/routines/case)
* [if](/sql/routines/if)
* [iterate](/sql/routines/iterate)
* [leave](/sql/routines/leave)
* [loop](/sql/routines/loop)
* [repeat](/sql/routines/repeat)
* [return](/sql/routines/return)
* [set](/sql/routines/set)
* [while](/sql/routines/while)
* Nested [begin](/sql/routines/begin) blocks

## Examples

The following example computes the value `42`:

```sql theme={null}
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](/sql/routines/examples).

## See also

* [routines](/sql/routines/introduction)
* [function](/sql/routines/function)
