Search code examples
sqloracle-databasevarcharzero-padding

how to put specific number of characters in front of a string in pl/sql?


I want to fix a string to length of 20 characters after the operation. For example, if my string is 1455 then new string should be 00000000000000001455 (20 characters) with 16 0s in front. Or if my string is 12345678 then new string should be 00000000000012345678 (20 chars) with 12 0s in front.

I can do it in a user-defined function but I wonder if there is an easy way to do it in Oracle? I googled but couldn't find any similar solution. Any suggestions?


Solution

  • do it like this:

    select lpad('1455',20,'0') from dual;