Example 2 - Advanced SQL Engine - Teradata Database

SQL Operators and User-Defined Functions

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2023-04-27
dita:mapPath
qqu1556127655717.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1210
lifecycle
previous
Product Category
Teradata Vantage™

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);