Variable-length Character Data

From InterBase

Go Up to Character Data Types

InterBase supports two variable-length string data types: VARCHAR(<n>), or alternately CHAR(<n>) VARYING, and NCHAR(<n>), or alternately NATIONAL CHAR(<n>) VARYING.

InterBase provides SQL syntax that allows you to use BLOBs and VARCHAR data interchangeably. For more information, see Using BLOBs with VARCHAR Data.


VARCHAR(<n>) – also called CHAR VARYING(<n>), or CHARACTER VARYING(<n>) – allows you to store the exact number of characters that is contained in your data, up to a maximum of <n>. You must supply <n>; there is no default to 1.

If the length of the data within a column varies widely, and you do not want to pad your character strings with blanks, use the VARCHAR(<n>) or CHARACTER VARYING(<n>) data type.

InterBase converts from variable-length character data to fixed-length character data by adding spaces to the value in the varying column until the column reaches its maximum length <n>. When the data is read, InterBase removes the blanks.

The main advantages of using the VARCHAR(<n>) data type are that it saves disk space, and since more rows fit on a disk page, the database server can search the table with fewer disk I/O operations. The disadvantage is that table updates can be slower than using a fixed-length column in some cases.

The next statement illustrates the VARCHAR(<n>) data type:

 DEFAULT 'new'
 CHECK (ORDER_STATUS IN ('new', 'open',
 'shipped', 'waiting')), );


NCHAR VARYING(<n>) – also called NATIONAL CHARACTER VARYING (<n>) or NATIONAL CHAR VARYING(<n>) – is exactly the same as VARCHAR(<n>), except that the ISO8859_1 character set is used. Using NCHAR VARYING(<n>) is a shortcut for using the CHARACTER SET clause of CREATE TABLE, CREATE DOMAIN, or ALTER TABLE to specify the ISO8859_1 character set.

Advance To: