Differences between Oracle character types and their usage

Source: Internet
Author: User

Differences:
1. the length of CHAR is fixed, while the length of VARCHAR2 can be changed. For example, the storage string "abc", for CHAR (20 ), it indicates that the characters you store will occupy 20 bytes (including 17 null characters), while the same VARCHAR2 (20) takes up only 3 bytes, and 20 is the maximum value, when the characters you store are less than 20 characters, they are stored according to the actual length.
2. CHAR is more efficient than VARCHAR2.
3. Currently, VARCHAR is a synonym for varchar2. The industry standard VARCHAR type can store null strings, but oracle does not, although it reserves the right to do so in the future. Oracle has developed a data type VARCHAR2, which is not a standard VARCHAR. It changes the feature that can store NULL strings in the varchar column of the database to store NULL values. If you want backward compatibility, we recommend that you use VARCHAR2 instead of VARCHAR.

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.

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.