简体   繁体   English

为什么to_char(0,'B9999')的例外是0?

[英]Why is 0 an exception for to_char(0,'B9999')?

What makes the number 0 an exception to Oracle to_char(number,'B9999') mask? 是什么使数字0成为Oracle to_char(number,'B9999')掩码的例外? In this query 0 doesn't print at all. 在此查询中,根本不会显示0。

How can I left pad all my numbers including 0 with spaces? 我如何在所有数字(包括0)上加上空格? Is lpad() the only alternative? lpad()是唯一的选择吗?

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 ). 您可以使用to_char(yourVal,'999')格式模型来获取三位数整数的左填充空格( 前导零为空白,零值除外 )。

If you need more, than raise the number of nines upto number of digits within your integer values : 如果您需要的更多,除了将9的位数增加到整数值内的位数之外:

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

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM