BEGIN END Syntax - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905
[ label_name : ] BEGIN
  [ local_declaration ] [...]
  [ cursor_declaration ] [...]
  [ condition_handler ] [...]
  [ statement ] [...]
END [ label_name ] ;

Syntax Elements

label_name
An optional label for the BEGIN END compound statement.
The beginning label must be terminated by a colon character (:). An ending label is optional. However, if an ending label is specified, you must specify an equivalent beginning label.
The label of a BEGIN END statement cannot be reused for any statement within it.
Using label names for each BEGIN END statement is recommended if you specify nested compound statements in a stored procedure.
local_declaration
A local variable declared using the DECLARE statement, or a condition declared using the DECLARE CONDITION statement.
In the case of nested compound statements, variables and conditions declared in an outer compound statement can be reused in any inner compound statement.
Local variables can be qualified with the label of the compound statement in which the variable is declared. This helps to avoid conflicts that can be caused by the reuse of local variables in nested compound statements.
cursor_declaration
A cursor declared using the DECLARE CURSOR statement.
In the case of nested compound statements, a cursor declared in an outer compound statement can be reused in any inner compound statement.
condition_handler
A condition handler declared using the DECLARE HANDLER statement.
You can use BEGIN END compound statements inside a condition_handler to enclose condition handler action statements.
statement
Any one of the following:
  • DML, DDL or DCL statements supported by stored procedures. These include dynamic SQL statements.
  • Control statements, including BEGIN END.