Explanations of varchar2 () and nvarchar2 () in Oracle

Source: Internet
Author: User

Differences between nvarchar2 and varchar2 in Oracle
[Convert] 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 Chinese Characters

Char fixed-length character fields, up to 2000 bytes
The fixed-length character field of the nchar multi-byte character set. The length varies with the character set. It can contain a maximum of 2000 or 2000 characters.
Varchar2 can contain up to 4000 characters
The variable-length character field of the nvarchar2 multi-byte character set. The length varies with the character set. It can contain a maximum of 4000 or 4000 characters.
When should char be used and varchar2 be used?
Char and varchar2 are a contradictory unity, and they are complementary.
Varchar2 saves space than char, and is slightly less efficient than Char. That is, to achieve efficiency, a certain amount of space must be sacrificed, this is what we often say in database design, "Change space for efficiency '.
Although varchar2 saves space than char, if a varchar2 column is often modified and the length of the data to be modified is different each time, this will cause row migration, this causes redundant I/O, which should be avoided during database design and adjustment. In this case, it would be better to replace varchar2 with Char.

. Nvarchar/nvarchar2

Nvarchar and nvarchar2 are unfixed lengths.

Nvarchar does not distinguish Chinese and English. For example, if you define nvarchar (20), you can store 20 English letters, Chinese characters, or Chinese and English combinations. This 20 defines the number of characters rather than the number of bytes.

Nvarchar2 is basically the same as nvarchar. The difference is that the English letters in nvarchar2 also occupy two bytes.

Nvarchar/nvarchar2 for storing Chinese Characters

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.