Condition Handling Terms - 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™
Term Definition
Completion condition When the execution of an SQL statement, including a control statement, is completed without any fatal event, and the database response indicates success or OK with warnings.

After completion (other than successful completion) of a request, the SQLCODE contains the return code (warning code), the SQLSTATE is set to a value other than ‘00000’ representing the completion condition and the ACTIVITY_COUNT is set to either “0” or a nonzero value depending on the SQL statement.

Examples of completion condition:
  • An SQL statement, including a control statement, is executed with warnings.
  • Zero rows affected by an UPDATE or DELETE statement.
  • Zero rows returned by a SELECT INTO statement.
  • No data found on cursor fetch.
Condition Represents an error or informational state caused by execution of an SQL statement, including a control statement.

Exception conditions or completion conditions are raised to provide information in the status variables SQLSTATE, SQLCODE and ACTIVITY_COUNT about execution of the SQL statement including a control statement.

Condition handler A construct defined to execute one or more actions depending on the SQLSTATE value returned to an application or on the condition specified by condition_name in the handler declaration.

The handler first defines one or more conditions to be handled and then the associated actions. The actions are executed when the corresponding condition occurs during stored procedure execution.

If you do not care what particular SQLSTATE code is returned to the stored procedure when an exception condition occurs, you can specify the keyword SQLEXCEPTION instead of one or more specific SQLSTATE codes. SQLEXCEPTION is treated as a generic exception condition handler.

Condition name A mnemonic name that can be associated with an SQLSTATE code in a DECLARE CONDITION statement. If you do not associate an SQLSTATE value with the condition name, then it is used to represent a user-defined condition.

A condition name identifies the condition to be handled and can be used only in condition declarations, handler declarations, SIGNAL statements and RESIGNAL statements.

Condition value An SQLSTATE value which is a 5-character string literal.
Exception condition When the execution of an SQL statement, including a control statement, is unsuccessful. The database response indicates an ERROR or FAILURE.

After an exception condition is handled, the SQLCODE reflects the return code, the SQLSTATE is set to a value other than ‘00000’ representing the exception condition, and the ACTIVITY_COUNT is set to “0”.

Examples of exception conditions include:
  • Invalid cursor state
  • Divide-by-zero violation
  • String truncation (only in ANSI session mode)
  • Cardinality violation
Generic condition handler Handler declared to handle generic conditions, represented by the keywords SQLEXCEPTION, SQLWARNING, or NOT FOUND. These keywords are declared instead of one or more specific SQLSTATE codes.

SQLEXCEPTION represents all exception conditions.

SQLWARNING represents all completion conditions except successful completion and “no data found” completion conditions.

NOT FOUND represents all “no data found” completion conditions.

Successful completion When the database response to the execution of an SQL statement indicates success or “ok” without any warning or other non-fatal event.

After successful completion of a request, the SQLSTATE is set to '00000', SQLCODE is set to “0” and the ACTIVITY_COUNT is set to either “0” or a nonzero value depending on the SQL statement. The status variable values are unchanged for a control statement.

User-defined condition A condition defined by the user for handling situations that are specific to a stored procedure and that are not represented by any SQLSTATE value.

Related Information