开发者

Prepend a digit to the beginning of a field

开发者 https://www.devze.com 2023-03-25 04:42 出处:网络
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. H

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

精彩评论

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