Fixed-length Character Data
Go Up to Character Data Types
InterBase supports two fixed-length string data types:
CHAR(<n>), or alternately
CHARACTER (<n>), and
NCHAR(<n>), or alternately
CHAR(n) or CHARACTER(n)
CHARACTER(<n>) data type contains character strings. The number of characters <n> is fixed. For the maximum number of characters allowed for the character set that you have specified, see Character Sets and Collation Orders.
When the string to be stored or read contains less than <n> characters, InterBase fills in the blanks to make up the difference. If a string is larger than <n>, then the value is truncated. If you do not supply <n>, it will default to 1, so
CHAR is the same as
CHAR(1). The next statement illustrates this:
CREATE TABLE SALES (. . . PAID CHAR DEFAULT 'n' CHECK (PAID IN ('y', 'n'), …);
Trailing blanks InterBase compresses trailing blanks when it stores fixed-length strings, so data with trailing blanks uses the same amount of space as an equivalent variable-length string. When the data is read, InterBase reinserts the blanks. This saves disk space when the length of the data items varies widely.
NCHAR(n) or NATIONAL CHAR(n)
NCHAR(<n>) is exactly the same as
CHARACTER(<n>), except that it uses the
ISO8859_1 character set by definition. Using
NCHAR(<n>) is a shortcut for using the
CHARACTER SET clause to specify the ISO8859_1 character set for a column.
The next two
CREATE TABLE examples are equivalent:
CREATE TABLE EMPLOYEE (… FIRST_NAME NCHAR(10), LAST_NAME NCHAR(15), …); CREATE TABLE EMPLOYEE (… FIRST_NAME CHAR(10) CHARACTER SET 'ISO8859_1', LAST_NAME CHAR(15) CHARACTER SET 'ISO8859_1', …);