Oracle, adding leading zeros to string (not number)

Deadly 提交于 2019-12-09 05:14:23

问题


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.

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?

Thanks in advance .


回答1:


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.

See: http://www.techonthenet.com/oracle/functions/lpad.php



来源:https://stackoverflow.com/questions/23814518/oracle-adding-leading-zeros-to-string-not-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!