Example: FNC_GetXMLByte and FNC_SetXMLByte - Teradata Vantage - Analytics Database

SQL External Routine Programming

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

The following UDF takes an XML parameter as input, retrieves the XML value in binary form, and sets the return XML value in binary form. The UDF assumes the XML size is small enough to be read using a single read.

CREATE FUNCTION xmlUDF6(P1 XML)
RETURNS XML
NO SQL
PARAMETER STYLE SQL
DETERMINISTIC
LANGUAGE C
EXTERNAL NAME 'CS!xmlUDF6!xmlUDF6.c';

void xmlUDF6(XML_HANDLE* xml_handle,
             XML_HANDLE* return_handle,
             int* indicator_thisXML,
             int* indicator_returnValue,
             char    sqlstate[6],
             SQL_TEXT    extname[129],
             SQL_TEXT    specific_name[129],
             SQL_TEXT    error_message[257] )
{
     FNC_XMLSize_t xmlSize;
     byte* xmlBuffer;
     FNC_XMLSize_t xmlBufferSize;
     int numLobs;

    /* Get the XML Size */
      FNC_GetXMLInfo(*xml_handle, &xmlSize, &numLobs); 

     if(numLobs ==1 )
     {  /* Return null if a LOB is passed in */
        *indicator_returnValue = -1;
         return;
     }

    /* Read the XML value */
     xmlBuffer = (byte*)FNC_Malloc(xmlSize);
     xmlBufferSize = xmlSize;
      FNC_GetXMLByte(*xml_handle,xmlBuffer, xmlBufferSize, &xmlSize); 
                                                                                                                           
     /* Set the return value */
      FNC_SetXMLByte(*return_handle, xmlBuffer, xmlSize); 
    *indicator_returnValue = 0;
     FNC_free(xmlBuffer);
}