17.00 - compound statement - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Advanced SQL Engine
Teradata Database
Release Number
September 2020
Content Type
Programming Reference
Publication ID
English (United States)
Last Update

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 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.
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.
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.
Terminating keyword for a BEGIN-END compound statement.