,varchar2 (n): This data type is used to define a variable-length string where n is used to specify the length of a string with a maximum value of 32767 bytes. When you use this data type to define a variable, you must specify a length. It is important to note that when you manipulate a varchar2 table column using that data type in PL/SQL , its maximum length is no more than 4000 bytes. dbms_output.put_line output string, the maximum length of output allowed is four bytes.
2, 2, char (n): Used to define a fixed-length string. where n is used to specify the length of the string, and its maximum value is 32767 bytes. When you use this data type to define a variable, if n is not specified, Its default is 1,when you use the data type in a PL/SQL block to manipulate Char table column, its value does not exceed the length of the number of bytes.
The following is a search for information on the Internet:
Difference:
1、VARCHAR2 is variable. For example char and varchar2, also stores ' abc ' for char storage string with 3 bytes, leaving 17 bytes with blanks; < Span style= "FONT-FAMILY:CALIBRI;" >varchar2 actually occupies 3 bytes, 20 is only the maximum length when the storage string is less than 20 a byte, it is stored as the actual string number of bytes.
2,CHAR efficiency is slightly higher than the efficiency of VARCHAR2 .
3, the currentVARCHARIsVARCHAR2The synonyms. Industry-Standardvarchar type can store an empty string, but Oracle does not do this, although it retains the right to do so later. oracle has developed a data type varchar2 , this type is not a standard varchar , which will be in database in varchar The column can store an attribute of an empty string instead of storing null value. If you want to have backward compatibility capabilities, oracle recommended varchar2 instead of varchar .
When to use CHAR or VARCHAR2:
VARCHAR2ThanCHARSpace saving, more efficient thanchar will be slightly worse, that is, to achieve efficiency, you have to sacrifice a certain amount of space, which is what we often say in database design Span lang= "en-US" > with space efficiency ' .
VARCHAR2 although char saves space, but if a varchar2 columns are often modified, And the length of each modified data is different, this will cause Row migration ' (Row migration) phenomenon, which causes superfluous i/o , is the database design and adjustment in order to avoid, in this case with char instead of varchar2 would be better.
Char (n) and VARCHAR2 (n) differences (GO)