Skip to content
Advertisement

DB2 leading zeroes [closed]

How to trim only zeroes in a leading position in a string?

I’m writing a DB2 script that removes all leading zeroes from a string that could be only 13 characters long. What I wrote so far:

ltrim(replace(Field, ‘00000’,”))

That works as follows:

0000012345678111 -> 12345678111
0000012300000174 -> 123174

Now, I need to delete ONLY the five leading zeroes, not the zeroes in the middle and I already tried to convert to decimal, but if I have, for example, only two zeroes leading, I want to leave them in the same position.

For example (converting to decimal) :

001234566890000 -> 1234566890000

I want no Changes in the left string.

How could I solve it?

Thanks

Advertisement

Answer

I found the Solution by myself. I’ve used nested function:

substr( replace( ltrim( replace(Field,'00000', ' ')), ' ', '0'), 1, 13)
(please, i can’t indent properly from My smartphone, could someone do it for me? Thanks)

This solve My question

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement