Example 2 - Analytics Database - Teradata Vantage

SQL Operators and User-Defined Functions

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2024-04-05
dita:mapPath
xub1628111590556.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
drp1544241916620
lifecycle
latest
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);