2011-03-14 47 views
0

该可选显示宽度可被用于通过应用 显示具有比左填充它们与 空间为 列指定的宽度小 宽度 整数值。显示宽度在MySQL中是否真正起作用?

显示宽度在MySQL中是否真正起作用?

`type` tinyint(2) NOT NULL, 

mysql> select length(type) from wp_orders; 
+--------------+ 
| length(type) | 
+--------------+ 
|   1 | 
+--------------+ 
1 row in set (0.00 sec) 

在我看来,这length(type)应至少2它是否工作正常?

回答

0

使用可选的显示宽度时,您需要指定zerofill。就我个人而言,我会在我的应用程序代码中执行所有格式。

drop table if exists foo; 
create table foo 
(
area_code smallint(4) unsigned zerofill not null default 0 
) 
engine=innodb; 

insert into foo (area_code) values (781),(727); 

select * from foo; 
+-----------+ 
| area_code | 
+-----------+ 
|  0781 | 
|  0727 | 
+-----------+