Example 1 - 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 definition and data:

CREATE TABLE pRecords (pname CHAR(30),
                       pkey INTEGER);
SELECT * FROM pRecords;

The output from the SELECT statement is:

pname                                  pkey
------------------------------  -----------
Tom                                       6
Bob                                       5
Jane                                      4

The following is the SQL definition of a scalar UDF that calculates the factorial of an integer argument:

CREATE FUNCTION factorial (i INTEGER)
RETURNS INTEGER
SPECIFIC factorial
LANGUAGE C
NO SQL
PARAMETER STYLE TD_GENERAL
NOT DETERMINISTIC
RETURNS NULL ON NULL INPUT
EXTERNAL NAME 'ss!factorial!factorial.c!F!fact'

The following query uses the scalar UDF expression to calculate the factorial of the pkey column + 1.

SELECT pname, factorial(pkey)+1 
FROM pRecords;

The output from the SELECT statement is:

pname                           (factorial(pkey)+1)
------------------------------  -------------------
Tom                                             721
Bob                                             121
Jane                                             25