Conditions and Condition Handlers | Teradata Vantage - Conditions and Condition Handlers - Advanced SQL Engine - Teradata Database

SQL Stored Procedures and Embedded SQL

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
vqj1592443206677.ditamap
dita:ditavalPath
vqj1592443206677.ditaval
dita:id
B035-1148
lifecycle
previous
Product Category
Teradata Vantageā„¢

Condition handlers can be either SQLSTATE-based, generic, or associated with an user-defined condition.

SQLSTATE-based Condition Handlers

Execution of the SQL statements within a stored procedure may result in certain completion, exception, or warning conditions. These conditions are posted to the SQLSTATE status variable. You can declare a condition handler and associate it with one or more SQLSTATE values. The condition handler will execute its actions when the conditions represented by the specified SQLSTATE values occur during stored procedure execution.

Generic Conditions and Handlers

Generic conditions are represented by the keywords SQLEXCEPTION, SQLWARNING, or NOT FOUND. You can declare a condition handler and associate it with one or more generic conditions instead of specific SQLSTATE values. The condition handler will execute its actions when the specified generic conditions occur during stored procedure execution.

Condition Handlers for Condition Names

SQLSTATE is a 5-character string value. You can declare a mnemonic name and associate it with an SQLSTATE value to make it easier to remember what condition the SQLSTATE value represents. You can declare a condition handler and associate it with one or more condition names. The condition handler will execute its actions when the conditions identified by the condition names or the associated SQLSTATE values occur during stored procedure execution.

User-Defined Conditions and Handlers

You can define custom conditions by declaring a condition name without associating it with an SQLSTATE value. This is useful if the conditions represented by the SQLSTATE values do not meet your needs. You can declare a condition handler and associate it with one or more user-defined conditions. The condition handler will execute its actions when the user-defined conditions occur during stored procedure execution. You can use the SIGNAL statement to explicitly raise a user-defined condition.

Related Information