15.10 - Example: Using the TD_ANYTYPE Parameter and RETURNS Clause Data Type in a UDF Definition - Teradata Database

Teradata Database SQL Data Definition Language Syntax and Examples

prodname
Teradata Database
vrm_release
15.10
created_date
December 2015
category
Programming Reference
featnum
B035-1144-151K

This function accepts the following data types as valid input parameters: CHARACTER, VARCHAR, and CLOB. See SQL External Routine Programming, B035-1147 for the C code for the ascii UDF.

The function then returns the numeric representation of the first character in the string_expr parameter according to the ASCII character encoding scheme.

The RETURNS clause type supported by this function is any of the following types: BYTEINT, SMALLINT, and INTEGER.

You can use this function to determine the numeric representation of CHARACTER, VARCHAR or CLOB data without knowing anything about the server character set for the data. The function can also return data requesting it as any of the following types: BYTEINT, SMALLINT or INTEGER.

     CREATE FUNCTION ascii (
       string_expr  TD_ANYTYPE)
     RETURNS TD_ANYTYPE
     LANGUAGE C
     NO SQL
     SPECIFIC ascii
     EXTERNAL NAME 'CS!ascii!ascii.c'
     PARAMETER STYLE SQL;

Because the TD_ANYTYPE parameter type can accept any supported data type, it is not necessary to create separate functions like ascii_char_latin(), ascii_char_unicode(), ascii_varchar_latin(), ascii_varchar_unicode(), ascii_clob_latin(), ascii_clob_unicode(), and so forth to handle multiple parameter data types.