Formatting an SQL numeric query result with an arbitrary number of decimal places

后端 未结 6 420
孤街浪徒
孤街浪徒 2021-01-15 04:51

I have a database table with these two columns:

  • Amount: numeric (18,0)
  • DecimalPlaces: numeric (18,0)

This table can store amounts in va

6条回答
  •  醉话见心
    2021-01-15 05:21

    How about?

    select 12345 amount, 2 decimalPlaces, substr( to_char( 12345 ), 1, length (to_char( 12345 ) ) - 2 ) || '.' || substr( to_char( 12345 ), -2 ) result from dual /

         amount decimalPlaces result
     ---------- ------------- ------
         12345              2 123.45
    

提交回复
热议问题