2011-03-14 33 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 | 
+-----------+ 
相關問題