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

SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
wgr1555383704548.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1144
lifecycle
previous
Product Category
Teradata Vantage™

This function accepts the following data types as valid input parameters: CHARACTER, VARCHAR, and CLOB. See Teradata Vantage™ - 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.