Home > database >  Replace only leading zeros with space in Oracle SQL
Replace only leading zeros with space in Oracle SQL

Time:11-12

I want to replace only the leading zeros of the select query.

I am using this:

SELECT REGEXP_REPLACE('00015201', '(0)', ' ') 
FROM DUAL;

But the result is

Column
--------
   152 1

I am expecting

Column
--------
   15201

CodePudding user response:

Use LTRIM to remove the zeros. Use LPAD to put blanks in their places.

select lpad(ltrim(numstr, '0'), length(numstr), ' ')
from (select '00015201' as numstr from dual);
  • Related