char 是定长型,varchar 是不定长型。简单例子
'aa '='aa' 吗?这个问题很有意思。可以相等也可以不等,char类型就相等,varchar类型就不等。
SQL> create table test( a char(3));
Table created
SQL> insert into test values ('aa ');
1 row inserted
SQL> insert into test values ('aa');
1 row inserted
SQL> commit;
Commit complete
SQL> select distinct a from test;
A
---
aa
SQL> select count(distinct a) from test;
COUNT(DISTINCTA)
----------------
1
SQL> select count(a) from test;
COUNT(A)
----------
2
显然char类型会认为2个是一样的。再看varchar
SQL> create table test1(a varchar2(3));
Table created
SQL> insert into test1 values('aa');
1 row inserted
SQL> insert into test1 values('aa ');
1 row inserted
SQL> commit;
Commit complete
SQL> select count(distinct a) from test1;
COUNT(DISTINCTA)
----------------
2
SQL> select count( a) from test1;
COUNT(A)
----------
2
很明显,2个值 是不一样的。distinct区分出来了。呵呵。
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/700806/viewspace-911989/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/700806/viewspace-911989/