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

查看:74
本文介绍了在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

推荐答案

将该字段更改回数字并使用

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

使用 LPAD()

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

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

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