16.20 - Example: Scalar Function with Parameter Style TD_GENERAL - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)

Here is a code excerpt that shows how to declare a scalar function that uses parameter style TD_GENERAL:

/*****  C source file name: substr.c  *****/
   
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
  
void udf_scalar_substr( VARCHAR_LATIN *inputString,
                        INTEGER       *start,
                        VARCHAR_LATIN *result,
                        char          sqlstate[6])
{
     ...
}

For a complete example of the scalar function, see Example: Basic Scalar Function.

The corresponding CREATE FUNCTION statement looks like this:

CREATE FUNCTION udfSubStr
  (inputString VARCHAR(512),
   start       INTEGER)
RETURNS VARCHAR(512)
LANGUAGE C
NO SQL
EXTERNAL NAME 'CS!substr!udfsrc/substr.c!F!udf_scalar_substr'
PARAMETER STYLE TD_GENERAL;