16.20 - Example Using FNC_LobLoc2Ref - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Advanced SQL Engine
Teradata Database
Release Number
Release Date
April 2020
Content Type
Programming Reference
Publication ID
English (United States)
#define BUFFER_SIZE 500

/* Aggregate intermediate record */
typedef struct
   FNC_LobLength_t length;
   LOB_REF         ref;
   BYTE            prefix[BUFFER_SIZE];
} intrec_t;
void Max_Blob(FNC_Phase          phase,
              FNC_Context_t      *fctx,
              LOB_LOCATOR        *x,
              LOB_RESULT_LOCATOR *result,
              int                *x_i,
              int                *result_i,
              char               sqlstate[6])
   intrec_t        *s1 = (intrec_t*) fctx->interim1;
   FNC_LobLength_t actsize;

   switch (phase)
   case AGR_INIT:
      s1 = (intrec_t *)FNC_DefMem(sizeof(intrec_t));
      s1->length = FNC_GetLobLength(*x);
      FNC_LobOpen(*x, &id, 0, BUFFER_SIZE);
      FNC_LobRead(id, s1->prefix, BUFFER_SIZE, &actsize);

      /* if the object length is less than the size
         allotted, pad the remaining bytes with zeros. */
      while (actsize < BUFFER_SIZE)
         s1->prefix[actsize++] = 0;
       FNC_LobLoc2Ref(*x, &s1->ref); 

   case AGR_DETAIL:





For a complete example that uses FNC_LobLoc2Ref, see C Aggregate Function Using LOBs .