CHAR, VARCHAR, VARCHAR2 type difference and use (transfer)

xiaoxiao2021-03-06  15

CHAR, VARCHAR, VARCHAR2 Type Differences and Use

(Sunnyxu original) 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? Char and varchar2 is a contradictory unity. The two are complementary relationships. VARCHAR2 is saved than Char, which is slightly less efficient than char, that is, if you want to get efficiency, you must sacrifice a certain space, this is We are often used in database design 'with spatial exchange efficiency'. Although VARCHAR2 saves space than Char, if a varchar2 column is often modified, and each time the length of the data is different, this will cause the 'row migration' (Row Migration), which causes extra I / O, is Database design and adjustment should be tried to avoid, in which case use char, it will be better.

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

New Post(0)