使所有自动递增整数与前导零相同的位数 [英] make all auto increment integers the same number of digits with leading zeros

查看:108
本文介绍了使所有自动递增整数与前导零相同的位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以将我的id列(自动递增)设置为使用mysql表中的前导零始终具有5位数字.因此,第一个值将是00001,然后是00002,以此类推,直到99999,而不是1,2,3,直到99999.谢谢

I was wondering if there was a way to set my id column(auto-incremented) to always have 5 digits using leading zeros in my mysql table. So the first value would be 00001 then 00002 and so on up to 99999 instead of 1,2,3 up to 99999. Thanks

推荐答案

您的ID列是一个数字值,因此它将始终具有相同的值.如果要以某种方式格式化整数,则必须将其格式化为SELECT的一部分.看一下LPAD函数.

Your ID column is a numeric value, so it's always going to have the same value. If you want the integer to be formatted a certain way, then you're going to have to do that formatting as part of the SELECT. Look at the LPAD function.

带有前导零的LPAD

这篇关于使所有自动递增整数与前导零相同的位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆