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.
fSqlType |
Length |
---|---|
SQL_CHAR |
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 |
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 |
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 |
6 (the size of the DATE_STRUCT or TIME_STRUCT structure). |
SQL_TYPE_TIMESTAMP |
16 (the size of the TIMESTAMP_STRUCT structure). |
SQL_GRAPHIC |
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 |
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) |