列大小Column Size

列 (或参数) 数值数据类型的大小定义为列或参数的数据类型使用的最大位数或数据的精度。The column (or parameter) size of numeric data types is defined as the maximum number of digits used by the data type of the column or parameter, or the precision of the data. 对于字符类型,这是数据的长度(以字符数表示);对于二进制数据类型,列大小定义为数据的长度(以字节为单位)。For character types, this is the length in characters of the data; for binary data types, column size is defined as the length in bytes of the data. 对于时间、时间戳和所有间隔数据类型,这是此数据的字符表示形式中的字符数。For the time, timestamp, and all interval data types, this is the number of characters in the character representation of this data. 下表显示了为每种简洁的 SQL 数据类型定义的列大小。The column size defined for each concise SQL data type is shown in the following table.

SQL 类型标识符SQL type identifier 列大小Column size
所有字符类型 [a],[b]All character types[a],[b] 列或参数的列或参数的定义或最大列大小 (包含在 SQL_DESC_LENGTH 描述符字段中) 。The defined or maximum column size in characters of the column or parameter (as contained in the SQL_DESC_LENGTH descriptor field). 例如,定义为 CHAR (10) 的单字节字符列的大小为10。For example, the column size of a single-byte character column defined as CHAR(10) is 10.
SQL_DECIMAL SQL_NUMERICSQL_DECIMAL SQL_NUMERIC 定义的位数。The defined number of digits. 例如,定义为数值 (10,3) 的列的精度为10。For example, the precision of a column defined as NUMERIC(10,3) is 10.
SQL_BIT [c]SQL_BIT[c] 11
SQL_TINYINT [c]SQL_TINYINT[c] 33
SQL_SMALLINT [c]SQL_SMALLINT[c] 55
SQL_INTEGER [c]SQL_INTEGER[c] 1010
SQL_BIGINT [c]SQL_BIGINT[c] 19 (如果有符号) ,则为 20 (如果无符号) 19 (if signed) or 20 (if unsigned)
SQL_REAL [c]SQL_REAL[c] 77
SQL_FLOAT [c]SQL_FLOAT[c] 1515
SQL_DOUBLE [c]SQL_DOUBLE[c] 1515
所有二进制类型 [a],[b]All binary types[a],[b] 列或参数的定义的或最大长度(以字节为单位)。The defined or maximum length in bytes of the column or parameter. 例如,定义为二进制 (10) 的列的长度为10。For example, the length of a column defined as BINARY(10) is 10.
SQL_TYPE_DATE [c]SQL_TYPE_DATE[c] 10 (yyyy-mm-dd 格式) 的字符数。10 (the number of characters in the yyyy-mm-dd format).
SQL_TYPE_TIME [c]SQL_TYPE_TIME[c] 8 (hh-mm ss 格式的字符数) ,或 9 + s (hh: mm: ss[. fff ...] 格式的字符数,其中 s 是) 的秒精度。8 (the number of characters in the hh-mm-ss format), or 9 + s (the number of characters in the hh:mm:ss[.fff...] format, where s is the seconds precision).
SQL_TYPE_TIMESTAMPSQL_TYPE_TIMESTAMP 16 (yyyy-mm-dd hh: mm 格式的字符数) 16 (the number of characters in the yyyy-mm-dd hh:mm format)

19 (yyyy-mm-dd hh: mm: ss 格式的字符数) 19 (the number of characters in the yyyy-mm-dd hh:mm:ss format)

or

20个 以上 ( yyyy-mm-dd hh: mm: ss[. ...] 格式的字符数,其中 s 是秒的精度) 。20 + s (the number of characters in the yyyy-mm-dd hh:mm:ss[.fff...] format, where s is the seconds precision).
SQL_INTERVAL_SECONDSQL_INTERVAL_SECOND 其中, p 为间隔的精度, s 为秒精度,如果 s= 0) ,则为 p (; + 如果 s>0) ,则为 p s+ 1 (。 [2-dWhere p is the interval leading precision and s is the seconds precision, p (if s=0) or p+s+1 (if s>0).[d]
SQL_INTERVAL_DAY_TO_SECONDSQL_INTERVAL_DAY_TO_SECOND 其中, p 是时间间隔的精度, s 为秒精度,9 +p (如果 s= 0) 或 10 +p + s (if >0) 。 [2-dWhere p is the interval leading precision and s is the seconds precision, 9+p (if s=0) or 10+p+s (if s>0).[d]
SQL_INTERVAL_HOUR_TO_SECONDSQL_INTERVAL_HOUR_TO_SECOND 其中, p 是时间间隔的精度, s 为秒精度,6 +p (如果 s= 0) 或 7 +p + s (if >0) 。 [2-dWhere p is the interval leading precision and s is the seconds precision, 6+p (if s=0) or 7+p+s (if s>0).[d]
SQL_INTERVAL_MINUTE_TO_SECONDSQL_INTERVAL_MINUTE_TO_SECOND 其中, p 是时间间隔的精度, s 为秒精度,3 +p (如果 s= 0) 或 4 +p + s (if >0) 。 [2-dWhere p is the interval leading precision and s is the seconds precision, 3+p (if s=0) or 4+p+s (if s>0).[d]
SQL_INTERVAL_YEAR SQL_INTERVAL_MONTH SQL_INTERVAL_DAY SQL_INTERVAL_HOUR SQL_INTERVAL_MINUTESQL_INTERVAL_YEAR SQL_INTERVAL_MONTH SQL_INTERVAL_DAY SQL_INTERVAL_HOUR SQL_INTERVAL_MINUTE p,其中 p 为间隔的起始精度。2-dp, where p is the interval leading precision.[d]
SQL_INTERVAL_YEAR_TO_MONTH SQL_INTERVAL_DAY_TO_HOURSQL_INTERVAL_YEAR_TO_MONTH SQL_INTERVAL_DAY_TO_HOUR 3 +p,其中 p 是间隔的起始精度。2-d3+p, where p is the interval leading precision.[d]
SQL_INTERVAL_DAY_TO_MINUTESQL_INTERVAL_DAY_TO_MINUTE 6 +p,其中 p 是间隔的起始精度。2-d6+p, where p is the interval leading precision.[d]
SQL_INTERVAL_HOUR_TO_MINUTESQL_INTERVAL_HOUR_TO_MINUTE 3 +p,其中 p 是间隔的起始精度。2-d3+p, where p is the interval leading precision.[d]
SQL_GUIDSQL_GUID 36 (aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee 格式的字符数) 36 (the number of characters in the aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee format)

[a] 对于在 ODBC 2.0 驱动程序中调用 SQLSetParam 的 odbc 1.0 应用程序,以及在 odbc 1.0 驱动程序中调用 SQLBindParameter 的 odbc 2.0 应用程序,如果 * 为 SQL_LONGVARCHAR 或 SQL_LONGVARBINARY 类型 SQL_DATA_AT_EXEC StrLen_or_IndPtr ,则必须将 ColumnSize 设置为要发送的数据的总长度,而不是此表中定义的精度。[a] For an ODBC 1.0 application calling SQLSetParam in an ODBC 2.0 driver, and for an ODBC 2.0 application calling SQLBindParameter in an ODBC 1.0 driver, when *StrLen_or_IndPtr is SQL_DATA_AT_EXEC for a SQL_LONGVARCHAR or SQL_LONGVARBINARY type, ColumnSize must be set to the total length of the data to be sent, not the precision as defined in this table.

[b] 如果驱动程序无法确定变量类型的列或参数长度,它将返回 SQL_NO_TOTAL。[b] If the driver cannot determine the column or parameter length for a variable type, it returns SQL_NO_TOTAL.

[c] 对于此数据类型,将忽略 SQLBindParameterColumnSize 参数。[c] The ColumnSize argument of SQLBindParameter is ignored for this data type.

[d] 有关间隔数据类型中列长度的一般规则,请参阅本附录前面的 时间间隔数据类型长度[d] For general rules about column length in interval data types, see Interval Data Type Length, earlier in this appendix.

为列 (或参数) 大小返回的值与任何一个描述符字段中的值均不对应。The values returned for the column (or parameter) size do not correspond to the values in any one descriptor field. 值可以来自 SQL_DESC_PRECISION 或 SQL_DESC_LENGTH 字段,具体取决于数据的类型,如下表所示。The values can come from either the SQL_DESC_PRECISION or the SQL_DESC_LENGTH field, depending on the type of data, as shown in the following table.

SQL 类型SQL type 对应的描述符字段Descriptor field corresponding to

列或参数大小column or parameter size
所有字符和二进制类型All character and binary types LENGTHLENGTH
所有数值类型All numeric types PRECISIONPRECISION
所有日期时间和间隔类型All datetime and interval types LENGTHLENGTH
SQL_BITSQL_BIT LENGTHLENGTH