开发者

Is the display width actually working in MySQL?

This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces.

Does the display width actually work in MySQL?

`type` tinyint(2) NOT NULL,

mysql> select length(type) from wp_orders;
+--------------+
| length(type) |
+--------------+
|            1 |
+--------------+
1 row in set (开发者_如何学JAVA0.00 sec)

It seems to me that length(type) should be at least 2 if it's working correctly?


You need to specify zerofill when using an optional display width. Personally i would do all my formatting in my application code.

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 |
+-----------+
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜