DB2 Data Type

Source: Internet
Author: User

DB2 built-in data types can be divided into numeric, character string, graphic string, binary string, or datetime ). There is also a special data type called datalink. The datalink value contains logical references to files not stored in the database.

Numeric data type Including smallint, integer, bigint, decimal (P, S), real, and double. All values have symbols and precision. Precision refers to the number of digits other than symbols in binary or decimal format. If the value of a number is greater than or equal to zero, the symbol is considered as positive.
* Small integer, smallint: A small integer is a two-byte integer with a precision of 5 digits. The range of a small integer is-32,768 to 32,767.
* Big integer, integer, or INT: A big integer is a four-byte integer with a precision of 10 digits. The range of a large integer is-2,147,483,648 to 2,147,483,647.
* Bigint: an integer of eight bytes with a precision of 19 characters. The range of a giant integer ranges from-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
* Decimal (P, S), Dec (P, S), numeric (P, S), or num (P, S ): A decimal value is a compressed decimal number, which has an implicit decimal point. The compressed decimal number is stored in binary-coded decimal, BCD) Notation variants. The decimal place depends on the precision (P) and decimal place (s) of the number ). Decimal place refers to the number of digits in the decimal part. It cannot be a negative number or be greater than the precision. The maximum precision is 31 bits. The decimal type ranges from-10 ** 31 + 1 to 10 ** 31-1.
* Single-precision floating-point. Real: A single-precision floating point is a 32-bit approximate value of a real number. The number can be zero, or in the range from-3.402e + 38 to-1.175e-37 or from 1.175e-37 to 3.402e + 38.
* Double-precision floating-point, double, double precision, or float: double-precision floating-point is a 64-bit approximate value of a real number. The number can be zero, or in the range from-1.79769e + 308 to-2.225e-307 or from 2.225e-307 to 1.79769e + 308.

String It is a byte sequence. A string includes a char (n) type fixed-length string and a variable-length string of the varchar (N), long varchar, or clob (n) type. The length of a string is the number of bytes in the sequence.
* Fixed-length string, character (n) or char (n): the length of a fixed-length string is between 1 and 254 bytes. If the length is not specified, it is regarded as 1 byte.
* Variable-length string: a variable-length string of the varchar (N), character varying (N), or char varying (n): varchar (n) type. The maximum length is 32,672 bytes.
* Long varchar: A long varchar string can contain up to 32,700 bytes.
* Character large object string (character large object string), clob (N [k | M | G]): clob is a variable-length string with a maximum length of 2,147,483,647 bytes. If only N is specified, 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 single-byte character set (sbcs) characters or mixed (Multi-byte character set (MBCS) and sbcs) characters. A graphical string is a sequence of Two-byte characters. Graphical strings include fixed-length graphical strings of the graphic (n) type and variable-length graphical strings of the vargraphic (N), long vargraphic, and dbclob (n) type. The length of a string is the number of double-byte characters in the sequence.
* Fixed-length graph string, graphic (n): the length of a fixed-length graph string ranges from 1 to 127 double-byte characters. If the length is not specified, it is considered to be 1 dubyte.
* Vargraphic (n): vargraphic (n) is a variable-length string with a maximum length of 16,336 double-byte characters.
* Long vargraphic: A long vargraphic string can contain up to 16,350 double-byte characters.
* Double-byte character large object string, dbclob (N [k | M | G]): the double-byte character large object is a variable-length double-byte character graphic string, up to 1,073,741,823 characters. If n is specified, 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 big DBCS (double-byte character set) characters. A binary string is a byte sequence. Binary strings include blob (N)-type variable-length strings, which are used to hold non-traditional data, slice, voice, or hybrid media, it can also accommodate user-defined types and structured data of user-defined functions.
* Binary large object, blob (N [k | M | G]): the Binary large object is a variable-length string, which can be up to 2,147,483,647 bytes. If n is specified, 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 Type Including date, time, and timestamp. Datetime values can be used in some arithmetic and string operations and are compatible with some strings, but they are neither strings nor numbers.
* Date: date is a three-part value (year, month, and day ). The year range is from 0001 to 9999. The range of month is from 1 to 12. The range of day is from 1 to n, where the value of N depends on the month. The date column is 10 bytes long.
* Time: Time is a value composed of three parts (hours, minutes, And seconds ). The hour range is from 0 to 24. The minute and second ranges from 0 to 59. If the hour is 24, the values of minute and second are both 0. The Time column is 8 bytes long.
* Timestamp: timestamp is a value composed of seven parts (year, month, day, hour, minute, second, And microsecond ). The year range is from 0001 to 9999. The range of month is from 1 to 12. The range of day is from 1 to n, where the value of N depends on the month. The hour range is from 0 to 24. The minute and second ranges from 0 to 59. The microsecond part ranges from 000000 to 999999. If the hour is 24, the minute value, second value, and microsecond value are both 0. The timestamp column is 26 bytes long. String Representation of the datetime value: although the internal representation of the values of date, time, and timestamp is transparent to users, the date, time, and Timestamp can also be expressed in strings, char scalar functions (see "parts of speech" in SQL) can be used to create string representations of date and time values.
* A date value string is a string of no less than 8 characters starting with a number. The minus zero in the month and day of the date value can be omitted.
* A Time Value string starts with a number and is a string of no less than four characters. The hour part of the time value can be omitted, and the second part can be completely omitted. If the second value is not specified, it is regarded as 0.
* The string of the time stamp value indicates a string starting with a number and with a length of not less than 16 characters. The complete time stamp string is represented as a yyyy-mm-dd-hh.mm.ss.nnnnnn. The zeros in front of the month, day, or hour of the time stamp value can be omitted, and the microseconds can be truncated or completely omitted. If the microsecond part of the timestamp value is omitted at the end of zero, it is assumed that the number of vacant digits is 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.