16.20 - Example 2 - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Operators and User-Defined Functions

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Administration
Programming Reference
Publication ID
B035-1210-162K
Language
English (United States)

Consider the following table and function definitions:

CREATE TABLE T1 (intCol INTEGER, 
                 varCharCol VARCHAR(40) CHARACTER SET UNICODE);
CREATE TABLE T2 (intCol INTEGER, 
                 decimalCol DECIMAL (10, 6));
CREATE FUNCTION myUDF1 (A INTEGER, B TD_ANYTYPE) 
RETURNS TD_ANYTYPE;
CREATE FUNCTION myUDF2 (A TD_ANYTYPE, B TD_ANYTYPE) 
RETURNS TD_ANYTYPE;

The following invocation of myUDF1 uses the RETURNS data_type clause to specify the UDF return type to be DECIMAL(10,6).

SELECT (myUDF1 (T1.intCol, T2.decimalCol) RETURNS DECIMAL(10,6)); 

The following invocation of myUDF2 uses the RETURNS STYLE clause to specify the UDF return type to be the data type of the T1.varCharCol column, which is VARCHAR(40) CHARACTER SET UNICODE.

SELECT (myUDF2 (T1.varCharCol, T2.decimalCol)
   RETURNS STYLE T1.varCharCol);