簡體   English   中英

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

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

是什么使數字0成為Oracle to_char(number,'B9999')掩碼的例外? 在此查詢中,根本不會顯示0。

我如何在所有數字(包括0)上加上空格? 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 ;

您可以使用to_char(yourVal,'999')格式模型來獲取三位數整數的左填充空格( 前導零為空白,零值除外 )。

如果您需要的更多,除了將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

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM