CREATE/REPLACE FUNCTION Examples | Teradata Database - Example: Creating a Function from Input Arguments - Teradata Database

SQL Data Definition Language Syntax and Examples

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Database
Release Number
20.00
Published
June 2025
ft:locale
en-US
ft:lastEdition
2026-09-23
dita:mapPath
mbm1747160743883.ditamap
dita:ditavalPath
jlp1749501702948.ditaval
dita:id
mdr1472255012272
lifecycle
latest

This example takes variable input arguments based on input from a previous correlated subquery in the FROM clause of a SELECT request, that is not shown. The function definition inputs XML text, which it then parses to extract a customer ID, store number, and the set of items purchased. The output produces one row per item purchased, with the columns being based on existing columns in the table defined in the function definition.

    CREATE FUNCTION xml_extract( xml_text VARCHAR(64000))
      RETURNS TABLE (cust_id INTEGER,
                     store   INTEGER,
                     item    INTEGER)
    LANGUAGE C
    NO SQL
    EXTERNAL;