向 MySQL 列中的某些值添加前导零 [英] Adding a leading zero to some values in column in MySQL

查看:33
本文介绍了向 MySQL 列中的某些值添加前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以 CSV 格式发送给我的 CSV 文件.感兴趣的字段是 8 位数字.其中一些以 0 开头.该字段以数字形式发送.所以,我现在去掉了一些前导零.

I have a CSV file sent to me in CSV. The field of interest is 8 digits. Some of those started with a 0. The field was sent numeric. So, I now have dropped some leading zeros.

我已经将该字段转换为 varchar.我现在需要这样做:

I already converted the field to varchar. I now need to do this:

我现在有这个:

12345678
1234567

我需要这个:

12345678
01234567

推荐答案

将字段改回数字并使用 ZEROFILL 保留零

Change the field back to numeric and use ZEROFILL to keep the zeros

使用LPAD()

SELECT LPAD('1234567', 8, '0');

这篇关于向 MySQL 列中的某些值添加前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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