VARCHAR

 

VARCHAR data type is similar to the CHAR data type and is also used to store character strings. The size of the VARCHAR variable is limited by 65534 characters. You can declare the maximum size of a VARCHAR variable by using (size) parameter. A string stored in this variable can be shorter that the declared size, but it cannot be longer. If you do not specify the size explicitly, the default size will be used which is equal to 1.

 

The size parameter of VARCHAR data type indicates the storage that will be reserved in the system for the variable declared as a VARCHAR. The reserved VARCHAR declaration does not affect the behavior of the 4GL syntax, but it may affect the behavior of a database which contains a column declared as VARCHAR.

 

VARCHAR values are compared in the same way as CHAR values, spaces are added to the end of the shorter value until both values are equal in lengths. A VARCHAR value can be compared only with a CHAR, VARCHAR or STRING value. If a VARCHAR variable consists only of white spaces, the trim() function or the CLIPPED operator applied to it will change its value to NULL.

 

There are some other features that differentiate VARCHAR data type from the CHAR data type:

 

Usually VARCHAR data type requires 1 byte per character, so the size in bytes is equal to the size in characters, but in some East Asian locales a character may require more than one byte to be stored. Some white space characters can also occupy more than one byte.