The CHAR data type stores any string of letters, numbers, and symbols. It can store single-byte and multibyte characters, based on the database locale. (For more information on East Asian locales that support multibyte code sets, see Multibyte Characters with VARCHAR .)
A CHAR(n) column has a length of n bytes, where 1 ≤ n ≤ 32,767. If you do not specify n, CHAR(1) is the default length. Character columns typically store alphanumeric strings, such as names, addresses, phone numbers, and so on. When a value is retrieved or stored as CHAR(n), exactly n bytes of data are transferred. If the string is shorter than n bytes, the string is extended with blank spaces up to the declared length. If the data value is longer than n bytes, a data string of length n that has been truncated from the right is inserted or retrieved, without the database server raising an exception.
This does not create partial characters in multibyte locales. In right-to-left locales, such as Arabic, Hebrew, or Farsi, the truncation is from the left.
If you plan to perform calculations on numbers stored in a column, you should assign a number data type to that column. Although you can store numbers in CHAR columns, you might not be able to use them in some arithmetic operations. For example, if you insert a sum into a CHAR column, you might experience overflow problems if the CHAR column is too small to hold the value. In this case, the insert fails. Numbers that have leading zeros (such as some zip codes) have the zeros stripped if they are stored as number types INTEGER or SMALLINT. Instead, store these numbers in CHAR columns.
In general, the collating order for sorting CHAR values is the order of characters in the code set. (An exception is the MATCHES operator with ranges; see Collating VARCHAR Values.) For more information about collation order, see the IBM Informix: GLS User's Guide.
For multibyte locales, the database supports any multibyte characters in the code set. When storing multibyte characters in a CHAR data type, make sure to calculate the number of bytes needed. For more information on multibyte characters and locales, see the IBM Informix: GLS User's Guide.
CHAR values are compared to other CHAR values by padding the shorter value on the right with blank spaces until the values have equal length, and then comparing the two values, using the code-set order for collation.
A CHAR value can include tab, newline, whitespace, and nonprintable characters. You must, however, use an application to insert nonprintable characters into host variables and the host variables into your database. After passing nonprintable characters to the database server, you can store or retrieve them. After you select nonprintable characters, fetch them into host variables and display them with your own display mechanism.
If you try to display nonprintable characters with DB–Access, your screen returns inconsistent results. (Which characters are nonprintable is locale-dependent. For more information, see the discussion of code-set conversion between the client and the database server in the IBM Informix: GLS User's Guide.)
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]