以下のサンプルは、Teradata Databaseが2つのcircle_t UDTを面積の順序で整列するための整列機能を実装しています。この関数は、指定された半径に基づいて面積を計算し、その結果をFLOATデータ型で戻します。円がNULLの場合や、円のx属性、y属性、または半径属性がNULLの場合、関数から戻される結果はNULLになります。
/* File: c_order.c */
#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>
void circle_t_Ordering( UDT_HANDLE *circleUdt,
FLOAT *result,
int *indicator_circle,
int *indicator_result,
char sqlstate[6],
SQL_TEXT extname[129],
SQL_TEXT specific_name[129],
SQL_TEXT error_message[257])
{
INTEGER x, y, r;
int nullIndicator;
int length;
/* If circle is null, return null. */
if (*indicator_circle == -1) {
*indicator_result = -1;
return;
}
/* Verify that the x attribute is not null. */
FNC_GetStructuredAttribute(*circleUdt, "x", &x, SIZEOF_INTEGER, &nullIndicator, &length);
if (nullIndicator == -1) {
*indicator_result = -1;
return;
}
/* Verify that the y attribute is not null. */
FNC_GetStructuredAttribute(*circleUdt, "y", &y, SIZEOF_INTEGER, &nullIndicator, &length);
if (nullIndicator == -1) {
*indicator_result = -1;
return;
}
/* Get the radius attribute. */
FNC_GetStructuredAttribute(*circleUdt, "radius", &r, SIZEOF_INTEGER, &nullIndicator, &length);
if (nullIndicator == -1) {
*indicator_result = -1;
return;
}
*result = 3.14 * r * r;
}