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

后端 未结 4 531
[愿得一人]
[愿得一人] 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:32

    Be aware when using the 'fm' syntax it will not include any values after the decimal place unless specified using zeros. For example:

    SELECT TO_CHAR(12345, 'fm99,999.00') FROM dual                               
    

    returns: '12,345.00'

    SELECT TO_CHAR(12345, 'fm99,999.99') FROM dual                            
    

    returns: '12,345.'

    As you can see this would be an issue if you are expecting two zeros after the decimals place (maybe in fee reports for example).

提交回复
热议问题