CHAR and VARCHAR data types
Informix®
Informix supports the following character data types:
Informix data type | Description |
---|---|
CHAR(n) |
SBCS and MBCS character data (max is 32767 bytes) |
VARCHAR(n[,m]) |
SBCS and MBCS character data (max is 255 bytes) |
NCHAR(n) |
Same as CHAR , with specific collation
order |
NVARCHAR(n[,m]) |
Same as VARCHAR , with specific collation
order |
LVARCHAR(n) |
max size varies depending on the IDS version |
With Informix, both
CHAR/VARCHAR
and NCHAR/NVARCHAR
data types can be used to store
single-byte or multibyte encoded character strings. The only difference between
CHAR/VARCHAR
and NCHAR/NVARCHAR
is in how they use sorting:
N[VAR]CHAR
types use the collation order, while [VAR]CHAR
types
use the byte order.
The character set used to store strings in
CHAR/VARCHAR/NCHAR/NVARCHAR
columns is defined by the DB_LOCALE environment
variable.
Informix uses Byte Length Semantics (the size
N that you specify in [VAR]CHAR(N)
is expressed in bytes, not characters as in some
other databases)
IBM® DB2®
IBM DB2 supports following data types to store character data:
IBM DB2 data type | Description |
---|---|
CHAR(n) |
SBCS character data using the database character set, where n is specified in bytes (max is 255 bytes) |
VARCHAR(n) |
SBCS character data using the database character set, where n is specified in bytes (max is 32672 bytes) |
GRAPHIC(n) |
UNICODE/UCS-2 character data, where n is specified in characters (max is 127 characters) |
VARGRAPHIC(n) |
UNICODE/UCS-2 character data, where n is specified in characters (max is 16336 characters) |
Like Informix, IBM DB2 uses Byte Length Semantics to define the length
of CHAR/VARCHAR
columns. However, GRAPHIC
and
VARGRAPHIC
lengths are specified in characters (i.e. max number of double-byte
characters).
The character set used by DB2 to store
CHAR
and VARCHAR
data is defined in the database locale section
when creating a new database. If your application uses UTF-8, consider creating the DB2 database with the UTF-8 codeset.
DB2 can automatically convert from/to the client and server characters sets. In the client applications, you define the character set with the DB2CODEPAGE profile variable.
Solution
Informix
CHAR(N)
types must be mapped to DB2
CHAR(N)
types, and Informix
VARCHAR(N)
or LVARCHAR(N)
columns must be mapped to DB2
VARCHAR(N)
.
- DB2 does not support
NCHAR/NVARCHAR
types. If your programs create tables with these types, you must review your code. The DB2 driver does not automatically convert theNCHAR/NVARCHAR
Informix types toGRAPHIC/VARGRAPHIC
, because the meaning of the length is different. - Check that your database schema does not use
CHAR
orVARCHAR
types with a length exceeding the DB2 limits. Especially, the InformixCHAR
type has a very long size limit compared to DB2CHAR
.
When using a multibyte character set (such as UTF-8), if the DB2 database was created with the appropriate codeset (UTF-8), you can use the
CHAR/VARCHAR
columns, and user byte length semantics in programs. If the database
code set is non multibyte, you must use the GRAPHIC
and VARGRAPHIC
data types to store multibyte character data, and use character length semantics in BDL programs
with FGL_LENGTH_SEMANTICS=CHAR.
When extracting a database schema from a DB2 database, the
fgldbsch schema extractor uses
the size of the column in characters, not the octet length. If you have created a CHAR(10
(characters) )
column a in DB2 database using the
UTF-8 character set, the .sch file will get a size of 10, that will be interpreted by
FGL_LENGTH_SEMANTICS as either a number of bytes or characters.
Do not forget to properly define the database client character set, which must correspond to the runtime system character set.
See also the section about Localization.
CHAR/VARCHAR
type translation can be controlled with the following FGLPROFILE
entries:dbi.database.dsname.ifxemul.datatype.char = { true | false }
dbi.database.dsname.ifxemul.datatype.varchar = { true | false }
For
more details see IBM Informix emulation parameters in FGLPROFILE.