Setting the Value of a Distinct UDT Result | Teradata Vantage - Setting the Value of a Distinct UDT Result - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-27
dita:mapPath
rin1593638965306.ditamap
dita:ditavalPath
rin1593638965306.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

To set the value of a distinct UDT that is defined to be the result of a UDF, follow these steps.

IF the distinct type … THEN …
does not represent a LOB
  1. Allocate a buffer using the C data type that maps to the underlying type of the distinct UDT.
  2. Place the return value into the buffer.
  3. Call FNC_SetDistinctValue to set the value of the UDT to the return value in the buffer you allocated.
represents a LOB
  1. Declare a LOB_RESULT_LOCATOR to hold the locator of the distinct type.
  2. Call FNC_GetDistinctResultLob to set the LOB_RESULT_LOCATOR to the locator of the distinct UDT.
  3. Follow the steps in Appending Data to a Large Object Result to append the return data using the LOB locator.

For detailed information on FNC_SetDistinctValue and FNC_GetDistinctResultLob, see C Library Functions.

The following code excerpt sets the value of a distinct UDT that represents a FLOAT:

void meters_t_toFeet( UDT_HANDLE    *metersUdt,
                      UDT_HANDLE    *resultFeetUdt,
                      char           sqlstate[6])
{
    FLOAT value;
    int length;
    /* Get the value of metersUdt. */
    FNC_GetDistinctValue(*metersUdt, &value, SIZEOF_FLOAT, &length);
    /* Convert meters to feet and set the result value */
    value *= 3.28;
    FNC_SetDistinctValue(*resultFeetUdt, &value, SIZEOF_FLOAT);

    ...
}