CHARACTER VARYING / LONG VARCHAR / VARCHAR - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
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 the middle of 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. Similarly, if you want to allow a binary zero character in the middle of a UDF result string, use the CHAR data type because a binary zero character in the middle of a VARCHAR result string will end 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.