DB2 10.5 for Linux, UNIX, and Windows

Data type length (CLI) table

In DB2 CLI applications, the length of a data type determines the size of a column. The length of a column is the maximum number of bytes that are returned to the application when data is transferred to its default C data type. For character data, the length does not include the null termination byte.

You can define the length of data types in DB2 CLI applications. Note that the length of a column might be different than the number of bytes required to store the data on the data source. The following table defines the length for each SQL data type.

Table 1. Length

fSqlType

Length

SQL_CHAR
SQL_VARCHAR
SQL_CLOB

The defined length of the column. For example, the length of a column defined as CHAR(10) is 10.

SQL_LONGVARCHAR

The maximum length of the column.

SQL_DECIMAL
SQL_NUMERIC

The maximum number of digits plus two. Since these data types are returned as character strings, characters are needed for the digits, a sign, and a decimal point. For example, the length of a column defined as NUMERIC(10,3) is 12.
SQL_DECFLOAT If the column is defined as DECFLOAT(16) then the length is 8. If the column is defined as DECFLOAT(34) then the length is 16.

SQL_SMALLINT

2 (two bytes).
SQL_INTEGER

4 (four bytes).

SQL_BIGINT

8 (eight bytes).

SQL_REAL

4 (four bytes).

SQL_FLOAT

8 (eight bytes).

SQL_DOUBLE

8 (eight bytes).

SQL_BINARY
SQL_VARBINARY
SQL_BLOB

The defined length of the column. For example, the length of a column defined as CHAR(10) FOR BIT DATA is 10.

SQL_LONGVARBINARY

The maximum length of the column.

SQL_TYPE_DATE
SQL_TYPE_TIME

6 (the size of the DATE_STRUCT or TIME_STRUCT structure).

SQL_TYPE_TIMESTAMP

16 (the size of the TIMESTAMP_STRUCT structure).

SQL_GRAPHIC
SQL_VARGRAPHIC
SQL_DBCLOB

The defined length of the column times 2. For example, the length of a column defined as GRAPHIC(10) is 20.

SQL_LONGVARGRAPHIC

The maximum length of the column times 2.

SQL_WCHAR
SQL_WVARCHAR
SQL_WLONGVARCHAR

The defined length of the column times 2. For example, the length of a column defined as WCHAR(10) is 20.

SQL_XML

0 (stored XML documents are limited to 2GB in size however)