开发者

MySQL field structure

开发者 https://www.devze.com 2023-01-10 15:49 出处:网络
I have a MySQL table data type integer field. the value is stored as 1, 2, 3 开发者_JAVA技巧.., 10000.

I have a MySQL table data type integer field. the value is stored as 1, 2, 3 开发者_JAVA技巧.., 10000.

I want to format it with starting from 00001, 00002, 0003 etc., (the whole number to be 5 digit).

Is there any function to do?

or how do i set it manually in phpMyAdmin..


You can change the column type to INT(5) ZEROFILL. From the documentation:

When used in conjunction with the optional extension attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(5) ZEROFILL, a value of 4 is retrieved as 00004.

Example:

CREATE TABLE table1(x INT(5) ZEROFILL);
INSERT INTO table1 VALUES(4);
SELECT * FROM table1;

Result:

00004
0

精彩评论

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