Why is Oracle's to_char() function adding spaces?

后端 未结 4 528
[愿得一人]
[愿得一人] 2021-02-03 17:25

Why is Oracle\'s to_char() function adding spaces?

select length(\'012\'), 
       length(to_char(\'012\')), 
       length(to_char(\'12\', \'000\')         


        
4条回答
  •  走了就别回头了
    2021-02-03 17:27

    The extra leading space is for the potential minus sign. To remove the space you can use FM in the format:

    SQL> select to_char(12,'FM000') from dual;
    
    TO_C
    ----
    012
    

    By the way, note that to_char takes a NUMBER argument; to_char('012') is implicitly converted to to_char(to_number('012')) = to_char(12)

提交回复
热议问题