compound statement - Advanced SQL Engine - Teradata Database

SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
wgr1555383704548.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1144
lifecycle
previous
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.