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

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

问题描述

我有一个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
1234567

我需要这样:

12345678

01234567

12345678
01234567

我使用mysql。

感谢

推荐答案

将字段更改为数字, a href =http://dev.mysql.com/doc/refman/5.1/en/numeric-type-overview.html> ZEROFILL 保留零

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

使用 LPAD()

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

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

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