The difference between char,varchar,varchar2 in Oracle

Source: Internet
Author: User

Difference:
1. The length of the char is fixed, and the length of the VARCHAR2 is changeable, for example, storing the string "abc", for Char (20), which means that the characters you store will account for 20 bytes (including 17 null characters), while the same VARCHAR2 (20) consumes only 3 bytes of length. 20 is the maximum value, which is stored as the actual length when the character you store is less than 20 o'clock.
2. The efficiency of char is slightly higher than that of VARCHAR2.
3. Currently varchar is synonymous with VARCHAR2. The industry standard varchar type can store an empty string, but Oracle does not, although it retains the right to do so later. Oracle has developed a data type of VARCHAR2, which is not a standard varchar, and it will store null values in the database in which the varchar column stores the empty string. If you want to have backward compatibility capabilities, Oracle recommends using VARCHAR2 instead of varchar.

When should I use char and when should I use VARCHAR2?
Char and VARCHAR2 are a pair of contradictory unity, the two are complementary relations.
VARCHAR2 saves space than Char and is slightly less efficient than char, that is, to be efficient, you have to sacrifice a certain amount of space, which is what we often call "space-for-efficiency" in database design.
Although VARCHAR2 is more space-saving than char, if a VARCHAR2 column is often modified and the length of each modified data is different, this causes a ' row-migration ' phenomenon, which creates redundant I/O, which is to be avoided in database design and tuning. , it would be better to use char instead of VARCHAR2 in this case.

A space is also automatically filled in char because you insert a space automatically in a Char field, but no space is deleted after the select.

The difference between char,varchar,varchar2 in Oracle

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.