DB2 string type in DB2 database

Source: Internet
Author: User
Tags db2

DB2 string is the basic knowledge in the DB2 database, the following is a description of the DB2 string for you, for your reference, if you are interested in the DB2 string, you may wish to see.

The DB2 string is a sequence of bytes. The DB2 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 that can be 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 DB2 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 characters large objects are variable-length double-byte character graphics strings 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]): A binary large object is a variable-length string up to 2,147,483,647 bytes in length. 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).

As if UTF-8 save Chinese will be 2 bit also will 3 bit, but do not know what reason will be different.


I use AS400 on the DB2 do test, directly with strSQL to run "Select length (' haha ') from TableA", the result is 6; However, if you enter "haha" in an application and log it to the Fielda of the table, select Length (Fielda) from TableA, the result is 4. It's really puzzling ...

Original from the "Bit network", reproduced please keep the original link: http://soft.chinabyte.com/database/492/12274992.shtml

DB2 string type in DB2 database

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.