首页 文章资讯内容详情

在MySQL中用零填充列的值

2026-06-04 1 花语

为此,请使用零填充的概念。它使用零填充字段的显示值,直到字段定义中设置的显示宽度

让我们首先创建一个表-

create table DemoTable626 (Value int(5) zerofill);

使用插入命令在表中插入一些记录-

insert into DemoTable626 values(9); insert into DemoTable626 values(12); insert into DemoTable626 values(567); insert into DemoTable626 values(3478);

使用select语句显示表中的所有记录-

select *from DemoTable626;

这将产生以下输出-

+-------+ | Value | +-------+ | 00009 | | 00012 | | 00567 | | 03478 | +-------+ 4 rows in set (0.00 sec)