Represents a variable length character string of length 0 to n for internal character storage. LONG VARCHAR specifies the longest permissible variable length character string for internal character storage.
Syntax
{ { VARCHAR | { CHARACTER | CHAR } VARYING } ( n ) [ { CHARACTER | CHAR } SET ] server_character_set | LONG VARCHAR | VARGRAPHIC ( n ) | LONG VARGRAPHIC } [ attributes [...] ]
- n
- The maximum number of characters or bytes allotted to the column defined with this server character set:
- For the LATIN server character set, the maximum value for n is 64000 characters.
- For the UNICODE and GRAPHIC server character sets, the maximum value for n is 32000 characters.
- For the KANJISJIS server character set, the maximum value for n is 32000 bytes.
- server_character_set
- The server character set for the character column being defined.
- attributes
- Appropriate data type, column storage, or column constraint attributes.
ANSI Compliance
VARCHAR is ANSI SQL:2011 compliant.
LONG VARCHAR, VARGRAPHIC, and LONG VARGRAPHIC are Teradata extensions to the ANSI SQL:2011 standard.
Storage
Character data is allocated either in terms of characters or in terms of bytes, depending on the server character set used. The number of bytes of storage per character also varies depending on the server character set, as illustrated by the following table.
Server Character Set | Server Form-of-Use | Server Space Allocation | Sharable Among Heterogeneous Clients? |
---|---|---|---|
LATIN | Fixed 8-bit LATIN | Character-based | Yes |
UNICODE | Fixed16-bit UNICODE | ||
GRAPHIC | Fixed 16-bit UNICODE | ||
KANJISJIS | Mixed single and multibyte KANJISJIS | Byte-based | Yes |
Any conversion to or from client system data types is done by Teradata Database. This data type supports international character sets.
External Representation of VARCHAR
Whenever a client application talks to Teradata Database, it indicates its character set (form-of-use for character data). The server returns all character data to the application in that form.
For information on the number of bytes exported for the VARCHAR type, see Teradata SQL Character Strings and Client Physical Bytes.
External Representation of LONG VARCHAR
For information on the number of bytes exported for the LONG VARCHAR type, see Teradata SQL Character Strings and Client Physical Bytes.
The following table shows how LONG VARCHAR data is represented for the various server character sets. Apart from these definitions, LONG VARCHAR strings behave identically to VARCHAR strings.
FOR this server character set … | The external representation for LONG VARCHAR is equivalent to … |
---|---|
|
VARCHAR(64000) |
|
VARCHAR(32000) |
External Representation of VARGRAPHIC
The following table lists the client representation for the IBM DB2 VARGRAPHIC type.
Determining the application definitions and client data types is the responsibility of the application programmer.
Define the length of the VARGRAPHIC(n) string as k, where 0 ≤ k ≤ n.
Client CPU Architecture | Client Internal Data Format |
---|---|
IBM mainframe | Two byte SMALLINT length count k followed by k DB2 GRAPHIC characters for a total of 2+2k EBCDIC bytes. |
Display Format
The default display format for VARCHAR(n) is X(n).
The default display format for LONG VARCHAR is either X(32000) or X(64000) depending on the server character set in effect.
For more information, see Data Type Default Formats.
Graphic Data
You can use the VARGRAPHIC or LONG VARGRAPHIC to represent multibyte character data.
VARGRAPHIC(n) is equivalent to VARCHAR(n) CHARACTER SET GRAPHIC. For best practice, define all VARGRAPHIC(n) data as VARCHAR(n) CHARACTER SET GRAPHIC.
The maximum value for n in a VARCHAR(n) CHARACTER SET GRAPHIC definition is 32000. There is no default length; therefore, omitting the length specification results in an error.
LONG VARGRAPHIC is equivalent to LONG VARCHAR CHARACTER SET GRAPHIC. For best practice, define all LONG VARGRAPHIC data as LONG VARCHAR CHARACTER SET GRAPHIC.
Related Topics
FOR information on … | SEE … |
---|---|
character literals | Character String Literals. |
conversion of external-to-internal and internal-to-external character data, including truncation and error handling | Teradata Vantage™ - Advanced SQL Engine International Character Set Support, B035-1125. |
Example: VARCHAR Data Type
The following statement creates a table that defines two VARCHAR columns: InfoKey and InfoData.
CREATE TABLE InfoTable (InfoKey VARCHAR(10) NOT NULL ,InfoData VARCHAR(16384) ) UNIQUE PRIMARY INDEX ( InfoKey );
The following statements insert character data of varying lengths into the InfoKey and InfoData columns:
INSERT INTO InfoTable ('001_5_799', 'Data for key 001_5_799'); INSERT INTO InfoTable ('2', 'Data for key 2');
Example: LONG VARCHAR Data Type
The following statement creates a table that defines a LONG VARCHAR column called InfoData.
CREATE TABLE InfoTable (InfoData LONG VARCHAR);