Length of SQL data types

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 character. Note that the length of a column can be different than the number of bytes that are required to store the data on the data source.

The following table defines the length for each SQL data type.

Table 1. Length of SQL data types
fSqlType Length
SQL_CHAR, SQL_VARCHAR SQL_CLOB The defined length, in bytes, of the column. For example, the length of a column defined as CHAR(10) is 10.
SQL_LONGVARCHAR The maximum length, in bytes, of the column.
SQL_DECIMAL, SQL_NUMERIC The maximum number of digits plus two bytes. Because 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_SMALLINT 2 bytes
SQL_INTEGER 4 bytes
SQL_BIGINT 8 bytes
SQL_REAL 4 bytes
SQL_ROWID 40 bytes
SQL_FLOAT 8 bytes
SQL_DOUBLE 8 bytes
SQL_DECFLOAT 23 bytes for DECFLOAT(16). 42 bytes for DECFLOAT(34).
SQL_BINARY, SQL_VARBINARY SQL_BLOB The defined length, in bytes, of the column. For example, the length of a column defined as CHAR(10) FOR BIT DATA is 10.
SQL_LONGVARBINARY The maximum length, in bytes, of the column.
SQL_TYPE_DATE, SQL_TYPE_TIME 6 bytes (the size of the DATE_STRUCT or TIME_STRUCT structure).
SQL_TYPE_TIMESTAMP 20 bytes (the size of the TIMESTAMP_STRUCT structure).
SQL_TYPE_TIMESTAMP_WITH_TIMEZONE The maximum number of bytes of the default C data type, which is SQL_C_TYPE_TIMESTAMP_EXT_TZ. The length is 24 bytes.
SQL_GRAPHIC, SQL_VARGRAPHIC, SQL_DBCLOB The defined length of the column times 2 bytes. For example, the length of a column defined as GRAPHIC(10) is 20.
SQL_LONGVARGRAPHIC The maximum length of the column times 2 bytes.
SQL_XML 0 bytes. However, stored XML documents are limited to a maximum size of 2 GB.