Example: Returning the SQLSTATE Result Code Value - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

Consider the following standard deviation aggregate function:

void STD_DEV ( FNC_Phase     phase,
               FNC_Context_t *fctx,
               FLOAT         *x,
               FLOAT         *result,
               char          sqlstate[6] )
{
     ...
}

You can use the sqlstate argument to return the SQLSTATE result code value.

For example, if the value of the phase argument is not a valid aggregation phase, you can set the value of the sqlstate argument to return a data exception:

strcpy(sqlstate, "U0005");

In a BTEQ session, the exception condition appears in the following format, where dbname is the name of the database of the function:

*** Failure 7504 in UDF/XSP  dbname.STD_DEV: SQLSTATE U0005: