CHARACTER VARYING / LONG VARCHAR / VARCHAR - 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ā„¢

C Data Type Definition

typedef Latin_Text VARCHAR_LATIN;
typedef Kanjisjis_Text VARCHAR_KANJISJIS;
typedef Kanji1_Text VARCHAR_KANJI1;
typedef Unicode_Text VARCHAR_UNICODE;

Usage

Character data types are passed using the standard null-terminated C string. The length of the C string is one more than the length of the SQL string.

If you want to allow a binary zero character in a UDF input parameter string, use the CHAR data type instead of VARCHAR, because your C code can more easily handle embedded binary zero characters in fixed-length strings. If you want to allow a binary zero character in a UDF result string, use the CHAR data type, because a binary zero character in a VARCHAR result string ends the string.

If the function result type is a varying length character type, then the result argument points to a data area with the size set to the maximum defined by the CREATE FUNCTION statement, plus one for the null string terminator. The function code must set the correct length of the result by using a null string terminator to end the string.

For LONG VARCHAR, the length is 64000 single byte characters or 32000 double byte characters.

This example uses VARCHAR in a UDF definition and C function declaration.

SQL Function Definition Equivalent C Function Declaration
CREATE FUNCTION F1 (
  A VARCHAR(30) )
RETURNS VARCHAR(12)
 ...;
void f1( VARCHAR_LATIN *a,
         VARCHAR_LATIN *result,
   ... )
{  ... }

Restrictions

Unicode strings use two bytes per character, including the null string terminator. The C library wide characters (wchar_t) are four bytes; therefore, you cannot use the C library wide character routines to manipulate Unicode strings.