VarChar data type

Official Content
This documentation is valid for:

Stores text values that vary in length. However, unlike with characters, it optimizes database storage.

Syntax

VarChar(M, N)

Where:
M
Specifies the possible maximum length that is predetermined by the DBMS you are using. If the length assigned to the attribute is greater than what is actually supported by the DBMS then the DBMS' maximum will be used.

N
Is the average length. This is used to optimize disk accesses in some DBMSs (particularly in the iSeries). The idea is that when the value of a varchar attribute is less than or equal to N, as N characters are stored (filled with blanks) in the file's record, only one disk access is required to read or store its value. If the value of the varchar attribute is greater than N, the first N are stored in the file's record and the rest are placed in an overflow area for which an additional access is required to ensure that the value is read as a whole.

Definition

The following table illustrates the properties used to define the Data Type:

Maximum length property
Average length property
Enable national language support property
Value range property
Initial value property
Picture Properties Group

Description

All functions and operators can be applied to this character data type.

The varchar data type is equivalent to character data types in all senses except in the way that they are stored in databases.

For those DBMSs that do not support this data type, it will be created as Character.

The following table illustrates the maximum length tolerated by each DBMS, with the last column showing the conversion done by GeneXus:

DBMS Max Length (M) Avg. Length (N) Conversion
ORACLE 4000 Not used Varchar(M) or Varchar2(M) 3
DB2 Universal Database 4000 Not used Varchar(M)
Informix 32000 1 0 to Max length Varchar(M,N)
SQL Server 8000 Not used Varchar(M)
DB2 UDB for iSeries / iSeries Native 320006 0 to Max length Varchar(M,N)
Visual FoxPro 254 2 Not used Character(M)
PostgreSQL   Not used Varchar(M)
MySQL

255 4

21000 5

   


1 If a column is defined in GX as Varchar(x), where x >= 255 (or 254, if it is part of an index), the field will be defined as lvarchar in the database. Besides, in this case, the average length is ignored.

2 The DBMS does not support strings that vary in length (except for Long Varchar). Strings are implemented with fixed lengths. That is, a character is generated taking the length from Max Length.

3 Varchar or Varchar2; depending on the Declare Varchar as Varchar 2 Data Store(Oracle) property.

4 Before Mysql 5.0.3.

5 In Mysql 5.0.3 and later versions.

6 16000 if Enable national language support property is Yes

Note

Attributes and variables assigned to these data types appear in reports/selectors as V (for example: V(40)). Although this data type makes use of the auto-resize facility in forms and print blocks, they can never display anything over 255 characters.

See also

DateTime data type
LongVarChar data type
Data types list


Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.