Oracle SQL 显示 2 位小数

问题描述 投票:0回答:1

如何显示整数的 2 位小数?我希望显示的列同时包含 int 和 float

例如: 3000显示为3000.00; 235.5显示为235.50; 123.126 显示为 123.12

oracle-sqldeveloper
1个回答
0
投票

一种选择是使用

to_char
功能和所需的格式掩码。例如:

SQL> with test (col) as
  2    (select 3000    from dual union all
  3     select 235.5   from dual union all
  4     select 123.126 from dual
  5    )
  6  select col,
  7         to_char(col, '999g999g990d00') result
  8  from test;

       COL RESULT
---------- ---------------
      3000        3.000,00
     235,5          235,50
   123,126          123,13

SQL>

另一种是使用

set numformat
:

SQL> set numformat 999g999g990d00
SQL> with test (col) as
  2    (select 3000   from dual union all
  3     select 235.5  from dual union all
  4     select 123.126 from dual
  5    )
  6  select col
  7  from test;

            COL
---------------
       3.000,00
         235,50
         123,13

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.