开发者

Prepend a digit to the beginning of a field

I need to add a "0" before a integer field in a MYSQL table. How do I update those fields so t开发者_C百科hey have a ) added to them? Thanks.


You can't unless you change the column type to string. However you can add the zero when reading the field:

SELECT CONCAT( '0', int_col ) FROM ....


If you want to format the output of all integer values in one column to a fixed column size, say 5, with leading zeroes for small numbers, use an ALTER TABLE statement like:

ALTER TABLE table MODIFY `col` INT(5) ZEROFILL;

Refer to MySQL 5.1 Reference Manual.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜