Data Types

Table 4-2 shows how the DB2 data types map to the standard ODBC data types. "Unicode Support" lists DB2 to Unicode data type mappings.

Table 4-2. DB2 Data Types 
DB2
ODBC
Bigint1
SQL_BIGINT
Blob2
SQL_LONGVARBINARY
Char
SQL_CHAR
Char() for Bit Data
SQL_BINARY
Clob3
SQL_LONGVARCHAR
Date
SQL_TYPE_DATE
Decimal
SQL_DECIMAL
Double
SQL_DOUBLE
Float
SQL_DOUBLE
Integer
SQL_INTEGER
Long Varchar
SQL_LONGVARCHAR
Long Varchar for Bit Data
SQL_LONGVARBINARY
Numeric
SQL_NUMERIC
Real
SQL_REAL
Smallint
SQL_SMALLINT
Time
SQL_TYPE_TIME
Timestamp
SQL_TYPE_TIMESTAMP
Varchar
SQL_VARCHAR
Varchar() for Bit Data
SQL_VARBINARY
XML4
SQL_LONGVARCHAR
1Supported on DB2 v8.x and higher for Linux/UNIX/Windows and DB2 V5R2 and higher for iSeries.
2Supported on DB2 v8.x and higher for Linux/UNIX/Windows; DB2 for z/OS; and DB2 V5R2 and higher for iSeries.
3On DB2 for Linux/UNIX/Windows versions previous to v8.1 and DB2 V5R2 for iSeries, only the first 32 KB of the Clob data are returned when fetching, and only 32 KB can be inserted and updated.
4Supported only on DB2 V9.1 for Linux/UNIX/Windows.

See "Retrieving Data Type Information" for information about retrieving data types.

Using the XML Data Type

By default, DB2 returns XML data to the driver encoded as UTF-8. To avoid data loss, an application must bind XML data as SQL_C_WCHAR. The driver then returns the data as either UTF-8 or UTF-16, depending on platform and application settings. If the application binds XML data as SQL_C_CHAR, the driver converts it to the client character encoding, possibly causing data loss or corruption. To prevent any conversion of XML data, the application must set the attribute XMLDescribeType (XDT) to SQL_LONGVARBINARY (-10) and bind the data as SQL_C_BINARY.