unwanted leading blank space on oracle number format

前端 未结 2 1614
走了就别回头了
走了就别回头了 2021-01-17 08:36

I need to pad numbers with leading zeros (total 8 digits) for display. I\'m using oracle.

select to_char(1011,\'00000000\') OPE_NO from dual;
select length(t         


        
相关标签:
2条回答
  • 2021-01-17 09:27

    Use FM (Fill Mode), e.g.

    select to_char(1011,'FM00000000') OPE_NO from dual;

    0 讨论(0)
  • 2021-01-17 09:30

    From that same documentation mentioned by EddieAwad:

    Negative return values automatically contain a leading negative sign and positive values automatically contain a leading space unless the format model contains the MI, S, or PR format element.


    EDIT: The right way is to use the FM modifier, as answered by Steve Bosman. Read the section about Format Model Modifiers for more info.

    0 讨论(0)
提交回复
热议问题