15.00 - UDF Handling of SQL Result Codes - Teradata Database

Teradata Database SQL Data Definition Language Detailed Topics

prodname
Teradata Database
vrm_release
15.00
category
Programming Reference
featnum
B035-1184-015K

UDF Handling of SQL Result Codes

Because UDFs are user‑written applications, it is the responsibility of the user‑written code to generate all success, warning, and exception messages.

The ANSI SQL:2011 standard defines a return code variable named SQLSTATE to accept status code messages. All condition messages are returned to this variable in a standard ASCII character string format.

All SQLSTATE messages are 5 characters in length. The first 2 characters define the message class and the last 3 characters define the message subclass.

For example, consider the SQLSTATE return code ‘22021’. The class of this message, 22, indicates a data exception condition. Its subclass, 021, indicates that a character not in the defined repertoire was encountered.

Be aware that SQL warnings do not abort a request, while SQL exceptions do abort a request.

Note: If you perform a UDF that is not set to run in protected mode, Teradata Database might not trap on any errors the function generates. If this happens, the likelihood that the error will crash your system is high. See “When to Specify Unprotected Mode” on page 15 for more information.

You should ensure that your UDFs always return valid SQLSTATE codes. Teradata Database does not map SQLSTATE values returned by user‑defined functions to their equivalent SQLCODE values. All SQLSTATE codes generated by UDFs are explicitly mapped to Teradata Database messages as indicated by the following table:

 

IF the UDF returns this type of SQL return code …

THEN the system maps it to this error message …

AND displays it in this format …

Warning

7505

*** Warning 7505 in dbname.udfname: SQLSTATE 01Hxx: <user function message text>

Exception

7504

*** Error 7504 in dbname.udfname: SQLSTATE U0xxx: <user function message text>

The string represented by <user function message text> is a user‑defined error message generated by the UDF.

The text represented by x characters in the SQLSTATE subclass is also assigned by the user‑written UDF code. All such characters must be either digits or uppercase Latin characters.

See SQL External Routine Programming for more information about coding UDFs.

See SQL Fundamentals for more information about SQL exception and warning codes.

See SQL Stored Procedures and Embedded SQL for more information about SQLSTATE and SQLCODE.