Example: Using FNC_GetXMLBlob to Retrieve an XML Type Input Value - 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ā„¢

The following function takes an XML type parameter, retrieves the BLOB representation of the XML, and returns the BLOB to the user.

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

void xmlUDF5(XML_HANDLE  *xml_handle,
              LOB_RESULT_LOCATOR *return_blob,
              int*       indicator_thisXML,
              int*       indicator_returnLOB,
              char       sqlstate[6],
              SQL_TEXT   extname[129],
              SQL_TEXT   specific_name[129],
              SQL_TEXT   error_message[257] )
{
     LOB_LOCATOR xmlBlob;
     BYTE buffer[100000];
     LOB_CONTEXT_ID id;
     FNC_LobLength_t actlen;
     int trunc_err = 0;
     FNC_XMLSize_t xmlSize;
     int numLobs;

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

     if(numLobs ==1 )
     {
    
      /* Read XML value */ 
       FNC_GetXMLBlob(*xml_handle,&xmlClob); 

      /* Use LOB FNC calls to read the XML BLOB and return it */                                                                                                                           
       FNC_LobOpen(*xmlBlob, &id, 0, 0);
       while( FNC_LobRead(id, buffer, 100000, &actlen) == 0 && !trunc_err)
          trunc_err = FNC_LobAppend(*return_blob, buffer, actlen, &actlen);

       FNC_LobClose(id);
      *indicator_returnLob = 0;
    }
 }