CHAR, VARCHAR, VARCHAR2 Type Differences and Use

zhaozj2021-02-16  66

the difference:

1. The length of Char is fixed, while Varchar2's length is variable, for example, stores a string "ABC", for char (20), indicating that you store characters will account for 20 bytes (including 17 empty characters), The same varchar2 (20) only occupies the length of 3 bytes, 20 is just the maximum value, when you store characters less than 20, press actual length storage.

2. The efficiency of Char is slightly higher than VARCHAR2.

3. At present, Varchar is a synonym of VARCHAR2. The industrial standard VARCHAR type can store empty strings, but Oracle does not do this, although it reserves the right to do so. Oracle has developed a data type VARCHAR2. This type is not a standard VARCHAR, which will change the characteristics of the VARCHAR column in the database to store NULL values. If you want to have backward compatible capabilities, Oracle recommends using varchar2 instead of VARCHAR.

??

When should I use char, when should I use VARCHAR2?

?????????? Is a pair of contradictory unity, both of which are complementary relationships.

Varchar2 saves space than Char, which is slightly less efficient than Char, that is, if you want to get efficiency, you must sacrifice a certain space, which is what we often say in the database design.

VARCHAR2 although saving space than Char, if a varchar2 column is often modified, and each time modified data is different, this can cause the 'row migration' (Row Migration) phenomenon, which causes extra I / O It is to try to avoid it in database design and adjustment. In this case, it will use char to replace VARCHAR2 more better.

转载请注明原文地址:https://www.9cbs.com/read-18640.html

New Post(0)