Differences between varchar, varchar2, nvarchar, and nvarchar2 in Oracle and other data types, varchar2nvarchar2

Source: Internet
Author: User

Differences between varchar, varchar2, nvarchar, and nvarchar2 in Oracle and other data types, varchar2nvarchar2
-- Varchar, varchar2 contact: 1. varchar/varchar2 is used to store variable-length strings

For example, if varchar (20) is saved to the string 'abc', this field occupies only 3 bytes in the database, not 20 bytes.

2. The maximum value of size is 4000, while the minimum value is 1. Its value indicates the number of bytes, for example

Varchar (20) indicates that up to 20 bytes of content can be stored.

Difference: 1. varchar2 processes all characters in two bytes (generally). varchar only occupies two bytes of Chinese characters and full-angle characters, and the numbers and English characters are one byte. VARCHAR2 treats empty strings as null, while varchar still processes empty strings. 3. the VARCHAR2 character must be stored in several bytes, depending on the character set used by the database,

For example, GBK occupies two bytes of Chinese characters and one English character

If it is UTF-8, Chinese characters generally occupy 3 bytes, English or 1.

However, we generally think it is two-byte processing, because we select the GBK encoding format by default during oracle installation, but when we verify the input string length on the page, or use the maximum length of the database design field except 3 as the maximum length ----- prevent different encoding formats from being set during database transplantation;

For example: VARCHAR2 (10). Generally, it can contain up to 5 Chinese characters and 10 characters.

-- Nvarchar, nvarchar2 contact: 1. nvarchar/nvarchar2 is used to store variable-length strings. 2. the maximum value of size is 4000, while the minimum value is 1. The value indicates the number of characters, not the number of bytes. these two types are more suitable for storing Chinese differences: 1. in nvarchar, if the characters are Chinese characters, they are generally calculated in 2 bytes, and the English numbers are calculated by yourself. all characters in nvarchar2 are calculated in 2 bytes. 3. although nvarchar2 occupies more space, it has better compatibility and is recommended for all applications. [note]

VARCHAR2 is a specific data type provided by Oracle. Oracle can ensure that VARCHAR2 is compatible with the data type up and down in any version.

VARCHAR is not recommended in Oracle.

The difference between NVARCHAR2 and VARCHAR2 is that NVARCHAR2 is related to character sets during length calculation. For example, if the database is a Chinese Character Set and the length is 10

1. NVARCHAR2 (10) can contain 10 Chinese characters. If it is used to store English letters, it can only contain 10 characters.

2. VARCHAR2 (10) can only contain 5 Chinese characters and 10 English characters.

VARCHAR2 (size)

The maximum length of a variable-length string is size bytes. the maximum size is 4000, and the minimum value is 1. You must specify the size of VARCHAR2;

NVARCHAR2 (size)

A variable-length string. Based on the selected national character set, the maximum length is size characters or bytes. the maximum size is determined by the number of bytes required for each character. The maximum size is 4000; you must specify the size of an NVARCHAR2;

NUMBER (p, s)

A value with a precision of p and a value range of s; a value with a precision of 1 to 38; A value range of s from-84 to 127;

For example, NUMBER (5, 2) indicates the integer part has a maximum of three digits and the fractional part has two digits;

NUMBER (5,-2) indicates the maximum value of the integer part of the NUMBER is 7. The reciprocal two digits of an integer are 0, and the first integer is rounded up.

NUMBER indicates that the default value is used, which is equivalent to NUMBER (5 );

LONG

Variable-length character data, which can be 2 GB in length;

DATE

Valid date range: From January 1, January 1, 4712 BC to January 1, December 31, 4712

RAW (size)

The size is the size of the original binary data. The maximum size is 2000 bytes. You must specify a size for RAW;

LONG RAW

Up to 2 GB of original binary data with a variable length;

CHAR (size)

The length of fixed-length character data is size bytes. the maximum size is 2000 bytes, and the minimum and default values are 1;

NCHAR (size)

It is also a fixed length. Defined according to Unicode standards

CLOB

A large character object that can contain single-byte characters. character sets of different widths are not supported. The maximum size is 4 GB.

NCLOB

A large character object that can contain single-byte characters. character sets of different widths are not supported. The maximum size is 4 GB.

BLOB

A large binary object; up to 4G bytes

BFILE

A locator that contains a large binary file, which is stored outside the database, so that the external LOB on the database server can be accessed by the ingress stream I/O. The maximum size is 4 GB.

Blob, clob, and nclob are three large objects (LOB) used to save large image files or formatted text files, such as Miceosoft Word documents and non-text files such as audio and video files, the maximum length is 4 GB. There are several types of LOB, depending on the type of bytes you use. Oracle 8i actually stores the data in the database. You can perform special operations such as reading, storage, and writing. The CLOB (Character Large Object) is used to store Character data that corresponds to the Character set defined by the database. (Similar to the long type) BLOB (Binary Large Object) can be used to store unstructured Binary data. (Similar to row and long row)

Related Article

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.