Basic Scalar Function Definition | SQL External Routine Programming | Vantage - Basic Scalar Function Definition - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-03-30
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
qnu1472247494689
lifecycle
latest
Product Category
Teradata Vantageā„¢

Here are the basic steps you take to define a scalar function:

  1. Define the SQL_TEXT constant.

    For more information, see SQL_TEXT Definition.

  2. Include the sqltypes_td.h header file.

    For more information, see Header Files.

  3. Include other header files that define macros and variables that the function uses.
  4. Define the function parameter list in the order that matches the parameter passing convention specified in the CREATE FUNCTION statement.

    For more information, see Scalar Function Parameter List.

  5. Implement the function and set the result to the appropriate value.
  6. If the function detects an error, set the:
    • sqlstate argument to an SQLSTATE exception or warning condition before the function exits.

      For more information, see Returning SQLSTATE Values.

    • error_message string to the error message text. The characters must be inside the LATIN character range. The string is initialized to a null-terminated string on input.
  7. If the function uses parameter style SQL, set the indicator_result argument as follows:
    Result indicator_result Value
    NULL -1.
    Not NULL 0.