1. 程式人生 > >mysql字串型別截斷測試

mysql字串型別截斷測試

create table test(name varchar(5));
insert into test values('bai'),('bai ');
mysql> select length(name) from test;
+--------------+
| length(name) |
+--------------+
|            3 |
|            4 |
+--------------+
2 rows in set (0.00 sec)

mysql> select concat("'",name,"'") from test;
+----------------------+
| concat("'",name,"'") | +----------------------+ | 'bai' | | 'bai ' | +----------------------+ mysql> create table test2(name char(5)); Query OK, 0 rows affected (0.02 sec) mysql> insert into test2 values('bai'),('bai '); Query OK, 2 rows affected (0.01 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> select concat("'",name,"'") from test2; +----------------------+
| concat("'",name,"'") | +----------------------+ | 'bai' | | 'bai' | +----------------------+ 2 rows in set (0.00 sec)

看到varchar會保留後面的空格,char會刪掉空格