The following example is based on the following ARRAY definition:
/*Oracle-compatible and Teradata syntax respectively: */ CREATE TYPE phonenumbers_ary AS VARRAY(5) OF CHAR(10); CREATE TYPE phonenumbers_ary AS CHAR(10) ARRAY[5]; /* This function sets the values of a set of consecutive elements from */ /* a source array phone_ary1 to the same range of values in phone_ary2.*/ void setMultiElement ( ARRAY_HANDLE *phone_ary1, ARRAY_HANDLE *phone_ary2, INTEGER *result, char sqlstate[6]) { long length; long bufferSize = SIZEOF_CHARACTER_LATIN_WITH_NULL(10) * 5; char *resultBuf; NullBitVecType *NullBitVector; array_info_t arrayInfo; long nullVecBufSize; bounds_t *arrayRange; bounds_t arrayScope[FNC_ARRAYMAXDIMENSIONS]; /* Call FNC_GetArrayTypeInfo first to find out the number of */ /* elements in the array. */ FNC_GetArrayTypeInfo(*phone_ary1, &arrayInfo, arrayScope); nullVecBufSize = arrayInfo.totalNumElements; resultBuf = (char*)FNC_malloc(bufferSize); arrayRange = (bounds_t*)FNC_malloc(sizeof(bounds_t)*arrayInfo.numDimensions); /* Allocate a new NullBitVector to pass to FNC_GetArrayElements. */ NullBitVector = (NullBitVecType*) FNC_malloc (nullVecBufSize); /* Set all members of NullBitVector to 0. */ memset(NullBitVector, 0, nullVecBufSize); /* Set values of arrayRange to correspond to the range [1:3] */ arrayRange[0].lowerBound = 1; arrayRange[0].upperBound = 3; /*Get elements within the range [1:3] of phone_ary1. */ FNC_GetArrayElements(*phone_ary1, arrayRange, resultBuf, bufferSize, NullBitVector, nullVecBufSize, &length); /* Set the elements in positions 1-3 of phone_ary2 to the same */ /* values as the corresponding elements in phone_ary1. */ FNC_SetArrayElementsWithMultiValues(*phone_ary2, arrayRange, (void*)resultBuf, length, NullBitVector, nullVecBufSize); ... }