DB2 Data types

Source: Internet
Author: User
Tags ranges

The built-in data types of the DB2 database are mainly classified as numeric (numeric), string (character string), graphic string (graphic string), binary string (binary strings), or DateTime. There is also a special data type called DATALINK. The DATALINK value contains a logical reference to a file that is stored outside the database.
Numeric data types include SMALLINT, INTEGER, BIGINT, DECIMAL (p,s), REAL, and DOUBLE. All values are signed and precision. Precision refers to the number of bits in binary or decimal except for symbols. If the value of a number is greater than or equal to zero, the symbol is assumed to be positive.
* Small integer, SMALLINT: Small integer is a two-byte whole number with a precision of 5 bits. The range of small integers ranges from 32,768 to 32,767.
* Large integer, Integer, or INT: The large integer is a four-byte whole number with a precision of 10 bits. Large integers range from 2,147,483,648 to 2,147,483,647.
* Jumbo, BIGINT: The Giant is a eight-byte integer with a precision of 19 bits. The range of the giant is from 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
* Decimal type, decimal (p,s), DEC (P,s), NUMERIC (p,s), or NUM (p,s): The decimal value is a compressed decimal number that has an implied decimal point. The compressed decimal number is stored as a variant of the two-decimal encoding (binary-coded DECIMAL,BCD) notation. The position of the decimal point depends on the precision (p) and decimal places (s) of the number. Decimal place refers to the number of decimal digits of the number of bits, it can not be negative, nor greater than the precision. The maximum accuracy is 31 bits. The decimal type ranges from -10**31+1 to 10**31-1.
* Single-precision floating point number (single-precision floating-point), real: single-precision floating-point numbers are 32-bit approximations of real numbers. The number can be zero, or within the range from -3.402E+38 to -1.175E-37 or from 1.175E-37 to 3.402E+38.
* Double-precision floating-point number (double-precision floating-point), double,double precision or float: double-precision floating-point numbers are 64-bit approximations of real numbers. The number can be zero, or within the range from -1.79769E+308 to -2.225E-307 or from 2.225E-307 to 1.79769E+308.
The string is a sequence of bytes. The string includes a fixed-length string of type CHAR (n) and a variable-length string of varchar (n), LONG VARCHAR, or CLOB (n) types. The length of the string is the number of bytes in the sequence.
* Fixed length string, CHARACTER (n) or CHAR (n): the length of the fixed-length string is between 1 and 254 bytes. If a length is not specified, it is considered to be 1 bytes.
* variable-length string, varchar (n), CHARACTER VARYING (n), or CHAR VARYING (n): VARCHAR (N)-type strings are variable-length strings up to 32,672 bytes long.
A string of *long Varchar:long VARCHAR type is a variable-length string up to 32,700 bytes long.
* Character Large object string (Character Large object string), CLOB (N[k M G]): CLOB is a variable-length string, up to 2,147,483,647 bytes long. If only n is specified, then the value of n is the maximum length. If NK is specified, the maximum length is n*1,024 (the maximum value of n is 2,097,152). If NM is specified, the maximum length is n*1,048,576 (the maximum value of n is 2,048). If NG is specified, the maximum length is n*1,073,741,824 (the maximum value of n is 2). CLOB is used to store data based on large single-byte character sets (Single-byte character Set,sbcs) characters or based on mixed (multibyte character set (MBCS) and SBCS) characters. A graphic string is a sequence of bytes that represents data for double-byte characters. The graphic string includes a fixed-length graphic string of type GRAPHIC (n) and a variable-length graphic string of type Vargraphic (n), long vargraphic, and Dbclob (n). The length of the string is the number of double-byte characters in the sequence.
* Fixed-length graphic string, GRAPHIC (n): the length of a fixed-length graphic string is between 1 and 127 double-byte characters. If you do not specify a length, it is considered to be 1 double-byte characters.
* variable length graphic string, Vargraphic (n): vargraphic (n) type string is a variable-length graphic string with a maximum length of up to 16,336 double-byte characters.
A string of type *long Vargraphic:long vargraphic is a variable-length graphic string with a maximum length of up to 16,350 double-byte characters.
* Double-byte character large object string, Dbclob (N[k M G]): Double-byte character large object is a variable-length double-byte character graphic string up to 1,073,741,823 characters long. If only n is specified, then n is the maximum length. If NK is specified, the maximum length is n*1,024 (the maximum value of n is 1,048,576). If NM is specified, the maximum length is n*1,048,576 (the maximum value of n is 1,024). If NG is specified, the maximum length is n*1,073,741,824 (the maximum value of n is 1). Dbclob is used to store data based on large DBCS (double-byte character set, double-byte character set) characters. A binary string is a sequence of bytes. Binary strings include variable-length strings of BLOB (n) types, which are used to accommodate non-traditional data, tablets, speech, or mixed media, and can also accommodate user-defined types and structured data for user-defined functions.
* Binary Large object, BLOB (N[k M G]): Binary Large objects are variable-length strings up to 2,147,483,647 bytes long. If only n is specified, then n is the maximum length. If NK is specified, the maximum length is n*1,024 (the maximum value of n is 2,097,152). If NM is specified, the maximum length is n*1,048,576 (the maximum value of n is 2,048). If NG is specified, the maximum length is n*1,073,741,824 (the maximum value of n is 2).
datetime data types include date, time, and TIMESTAMP. DateTime values can be used in some arithmetic and string operations and are compatible with certain strings, but they are neither strings nor numbers.
*date:date is a three-part value (year, month, and day). The year section ranges from 0001 to 9999. The month section ranges from 1 to 12. The day part is scoped from 1 to N, where the value of n depends on the month. A DATE column is 10 bytes long.
*time:time is a three-part value (hours, minutes, and seconds). The hours section ranges from 0 to 24. The Minutes and Seconds sections range from 0 to 59. If the hour is 24, the minute and second values are 0. The time column is 8 bytes long.
*timestamp:timestamp is a seven-part value (year, month, day, hour, minute, second, and microsecond). The year section ranges from 0001 to 9999. The month section ranges from 1 to 12. The day part is scoped from 1 to N, where the value of n depends on the month. The hours section ranges from 0 to 24. The Minutes and Seconds sections range from 0 to 59. The microsecond portion ranges from 000000 to 999999. If the hour is 24, then the minute value, the second value, and the microsecond value are all 0. The TIMESTAMP column has a length of 26 bytes. A string representation of a DateTime value: Although the internal representation of the value of date, time, and TIMESTAMP is transparent to the user, the date, timestamp, and time stamp can also be represented by a string, CHAR scalar function (see "Speech of the word (parts of speech)" in SQL ) can be used to create a string representation of a date-time value.
* The string representation of a date value is a string that starts with a number and is not less than 8 characters long. The month and day parts of the date value can be omitted from the preceding 0.
* The string representation of a time value is a string that starts with a number and is not less than 4 characters long. The hour portion of the time value preceding 0 can be omitted, and the second part can be omitted completely. If the value of the second is not specified, then it is considered to be 0.
* The string representation of a timestamp value is a string that starts with a number and is not less than 16 characters long. The full timestamp string representation is yyyy-mm-dd-hh.mm.ss.nnnnnn. The number of months, days, or hours of the timestamp value preceding 0 can be omitted, and microseconds can be truncated or omitted altogether. If the microsecond portion of any timestamp value is omitted at the end of 0, then the vacant digits are assumed to be zero

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.