Do not use the VARCHAR
data type. Use the VARCHAR2
data type instead. Although the VARCHAR
data type is currently synonymous with VARCHAR2
, the VARCHAR
data type is scheduled to be redefined as a separate data type used for variable-length character strings compared with different comparison semantics.
目前oracle推荐使用的是varchar2 ,不推荐使用varchar,虽然目前varchar和varchar2 有点类似,但是 以后会重新定义varchar类型。varchar2 最大支持4000个字节
varchar2(10):可变字节,如果你存入的字节是aa,那么实际占用空间只有2个字节,最大可以容纳10个字节,相比char 类型,比较节省空间
SQL> insert into t2 values(1,'a');
1 row created.
SQL> commit;
Commit complete.
SQL> select dump(name) from t1;
DUMP(NAME)
--------------------------------------------------------------------------------
Typ=1 Len=1: 97
char(10):如果你存入aa,那么实际占用空间就是10个字节,2个字节被aa占用,其他用空格来占用。Fixed-length character data of length size
bytes or characters. Maximum size
is 2000 bytes or characters. Default and minimum size
is 1 byte.
SQL> insert into t2 values(1,'a');
SQL> select dump(name) from t2;
DUMP(NAME)
--------------------------------------------------------------------------------
Typ=96 Len=20: 0,97,0,32,0,32,0,32,0,32,0,32,0,32,0,32,0,32,0,32
nchar(10): nchar 是确定长度类型,根据 unicode 标准所进行的定义,用给定整数代码返回unicode 字符.Fixed-length character data of length size characters. The number of bytes can be up to two times size for AL16UTF16 encoding and three times size for UTF8 encoding. Maximumsize is determined by the national character set definition, with an upper limit of 2000 bytes. Default and minimum size is 1 character.
SQL> alter table t2 modify(name nchar(10));
Table altered.
SQL> insert into t2 values(1,'aa');
1 row created.
SQL> select dump(name) from t2;
DUMP(NAME)
--------------------------------------------------------------------------------
Typ=96 Len=20: 0,97,0,97,0,32,0,32,0,32,0,32,0,32,0,32,0,32,0,32
nvarchar2(10):nvarchar2基本上等同于nvarchar,不同在于nvarchar2中存的英文字母也占两个字节。Variable-length Unicode character string having maximum length size
characters. The number of bytes can be up to two times size
for AL16UTF16
encoding and three times size
for UTF8
encoding. Maximum size
is determined by the national character set definition, with an upper limit of 4000 bytes.
SQL> insert into t2 values(1,'aa');
1 row created.
SQL> select dump(name) from t2;
DUMP(NAME)
--------------------------------------------------------------------------------