16.20 - Returning SQLSTATE Values - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Advanced SQL Engine
Teradata Database
Release Number
Release Date
April 2020
Content Type
Programming Reference
Publication ID
English (United States)

A Java UDF can throw a java.lang.SQLException with an exception number and message that are returned to Teradata Database and used to set the SQLSTATE value and error message.

Valid values for the SQLState field of the SQLException are in the range 38U00 to 38U99.

Here is an example:

public class UDFExample {

   public static Integer fact( Integer x )
   throws SQLException
      int factresult = 0;
      if (x != null)
         factresult = 1;
         throw new SQLException("Input value not valid", "38U01");
      return new Integer(factresult);



SQLException is the only valid exception that Java external routines can throw.