compound statement - Teradata Vantage - Analytics Database

SQL Data Definition Language Syntax and Examples

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-11-22
dita:mapPath
jco1628111346878.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
mdr1472255012272
lifecycle
latest
Product Category
Teradata Vantageā„¢

BEGIN-END statement enclosing a set of declarations and statements.

You can specify local variable declarations, cursor declarations, condition handler declarations and SQL and control statements within a compound statement.

Nesting of compound statements is allowed.

You can specify these options for a compound statement.

label_name
Label for a BEGIN-END compound statement in the procedure, or for an iteration statement (WHILE, LOOP, FOR and REPEAT).
The beginning label must be suffixed with a COLON character (:). An ending label is not mandatory, but if an ending label is specified, you must also specify an equivalent beginning label.
The label name of the BEGIN-END compound statement cannot be reused in an iteration statement. A label name cannot be reused within a group of nested compound statements or nested iteration statements, but can be reused for different non-nested iteration statements or non-nested compound statements.
Using label names for each BEGIN-END compound statement is recommended if you specify nested compound statements in an SQL procedure.
A local variable can be optionally qualified with the label of the corresponding compound statement in which the variable is declared. This helps in avoiding conflicts that might be caused by duplicate local variables in nested compound statements.
BEGIN
Keyword introducing a compound statement.
A compound statement defining the procedure body contains all the SQL statements and declarations of the procedure.
You must terminate a compound statement with the END keyword.
See Teradata Vantageā„¢ - SQL Stored Procedures and Embedded SQL, B035-1148 for details.
statement_list
Any of the following:
  • SQL DML, DDL, or DCL statements supported by SQL procedures, including dynamic SQL statements.

    You can also use the CALL statement invoking the procedure_name being created.

  • control statements, including the BEGIN-END compound statement.
You can use any number of statements in a statement_list. Each must be terminated by a SEMICOLON (;) character.
END
Terminating keyword for a BEGIN-END compound statement.