mysql中的字符串类型包括char、varchar、blob、text、enum、set类型

1、char和varchar类型:

字符串类型(M),其中M值得是所占用的字符数,varchar中是M+1字节

 

char可以是0-255任何值,vrachar可以是0-255(5.0.3之前)和0-65535(5.0.3之后)的值,在检索时,char会删除尾部的空格,而varchar会保留这些,如下实验:

 

root@localhost:cyz--01:11:14 >create table test(a char(10),b varchar(10));
Query OK, 0 rows affected (0.02 sec)

root@localhost:cyz--01:11:15 >insert into test values('ab ','ab ');
Query OK, 1 row affected (0.00 sec)

root@localhost:cyz--01:11:28 >select * from test;
+------+-------+
| a | b |
+------+-------+
| ab | ab |
+------+-------+
1 row in set (0.00 sec)

root@localhost:cyz--01:11:32 >select length(a) a,length(b) b from test;
+------+------+
| a | b |
+------+------+
| 2 | 5 |
+------+------+
1 row in set (0.11 sec)

posted on 2015-09-24 10:07  guols0612  阅读(197)  评论(0编辑  收藏  举报