17.00 - Example: Defining an SQL UDF With a Method in its RETURN Statement - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Release Date
September 2020
Content Type
Programming Reference
Publication ID
B035-1144-170K
Language
English (United States)

This example specifies the system-generated method zip in its RETURN statement.

First you must create the structured UDT address.

     CREATE TYPE address
     AS (street VARCHAR(20), zip CHARACTER(5))
     NOT FINAL;

Now you can create the SQL UDF zipcode, which specifies the system-generated method zip in its RETURN statement.

     CREATE FUNCTION test.zipcode (a address)
     RETURNS CHARACTER(5)
     LANGUAGE SQL
     DETERMINISTIC
     CONTAINS SQL
     SPECIFIC test.zipcode
     CALLED ON NULL INPUT
     SQL SECURITY DEFINER
     COLLATION INVOKER
     INLINE TYPE 1
     RETURN a.zip();