Oracle,在字符串(非数字)中添加前导零 [英] Oracle, adding leading zeros to string (not number)

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

问题描述

我正在使用Oracle(工作空间为TOAD),我需要对字符串进行缩短,如果它们被短接了10个字符,则添加前导零以使它们全部为10位数字字符串.

I am using Oracle (work space is TOAD) and I need to make my strings that if they are shorted then 10 characters then add leading zeros to make them all 10 digit strings.

例如,如果我有一个像这样的字符串: '12H89'必须为'0000012H89' 或者 "1234"为"0000001234"

For example if I have a string like this: '12H89' need to be '0000012H89' or '1234' to be '0000001234'

这怎么办?最好的方法是什么?

How can this be done? Whats the best way?

谢谢.

推荐答案

您可以为此使用LPAD函数,传入字符串,所需的长度以及填充字符.对于前导零的10位数字,则为:

You can use the LPAD function for that, passing in the string, the length you want it to be, and the character to pad it with. For 10 digits with leading zeroes this would be:

LPAD('12H89', 10, '0')

返回值是填充的字符串.

The return value is the padded string.

请参阅: http://www.techonthenet.com/oracle/functions/lpad. php

这篇关于Oracle,在字符串(非数字)中添加前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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