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

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

This function accepts the following data types as valid input parameters: CHARACTER, VARCHAR, and CLOB.

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.