What makes the number 0 an exception to Oracle to_char(number,'B9999') mask? In this query 0 doesn't print at all.
How can I left pad all my numbers including 0 with spaces? Is lpad()
the only alternative?
select to_char(0,'B09999') as num_fmt from dual union all
select to_char(0,'B9999') as num_fmt from dual union all
select to_char(300,'B9999') as num_fmt from dual union all
select to_char(-300,'B9999') as num_fmt from dual ;
You can use to_char(yourVal,'999')
format model to get left padded blanks for integers of three digits ( Leading zeros are blank, except for a zero value ).
If you need more, than raise the number of nines upto number of digits within your integer values :
select to_char(0,'999') as num_fmt from dual union all
select to_char('00','999') from dual union all
select to_char('016','999') from dual union all
select to_char(17,'999') from dual union all
select to_char(314,'999') from dual union all
select to_char(-314,'999') from dual;
NUM_FMT
-------
0
0
16
17
314
-314
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.