Example - 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
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantage™

The following code excerpt shows an external stored procedure that calls the FNC_GetAnyTypeParamInfo function to retrieve information about the TD_ANYTYPE arguments.

#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>

void xspwanytypefnc(void     *input1,
                    ...,
                    void     *result,
                    int      *indc_input1,
                    ...,
                    int      *indc_result,
                    char     sqlstate[6],
                    SQL_TEXT extname[129],
                    SQL_TEXT specific_name[129],
                    SQL_TEXT error_message[257])
{
   anytype_param_info_t paraminfo[2];
   int numunk;

   FNC_GetAnyTypeParamInfo(2*sizeof(anytype_param_info_t),&numunk,
      paraminfo);

   if(((paraminfo[1].datatype == CHAR_DT) ||
       (paraminfo[1].datatype == VARCHAR_DT)) &&
       (paraminfo[1].paramIndex == -1)&&
       (paraminfo[1].direction == OUT_PM)&&
       (paraminfo[1].charset == LATIN_CT))
   {
      /* Process the value based upon the data type */
      switch(paraminfo[0].datatype)
      {
         case BYTEINT_DT:
            strcpy ((char *)result,"Byteint");
            break;
            /* Do some processing */
            ...
      }
   }
}

The following shows the corresponding SQL procedure definition:

CREATE PROCEDURE xspwanytypefnc(IN a TD_ANYTYPE,
                                ...,
                                OUT result1 TD_ANYTYPE)
LANGUAGE C
NO SQL
PARAMETER STYLE SQL
EXTERNAL NAME 'CS!xspwanytypefnc!xspwanytypefnc.c';