请问我现在数据库  Table A 中有一个字段 amount ,数据格式是小数点 6位,我现在想从数据库取出数据,但显示的时候四舍五入法取小数点两位,我该怎么做,
如 Table A  
   amount        显示效果
   12.567000     12.57
   22.550000     22.55
   52.000000     52.00
我的项目 有oracle 和db2两种数据库, 请问我该怎么弄sql语气,才能对两种数据库都通用。。

解决方案 »

  1.   

    select round(amount ,2) from a
      

  2.   

     with tb as(
      select 12.567000 test from dual union all
      select 22.550000 from dual union all
      select 52.000000 from dual union all
      select 221.3 from dual union all
      select 52300 from dual)
     select round(test,2) from tb --如果你的数据中小数位不足两位 就显示原数据ROUND(TEST,2)
    -------------
            12.57
            22.55
               52
            221.3
            52300--如果要所有的列都显示两位小数 可以在sqlplus里用命令
    SQL> col sal format 9999.99; --将sal列显示为整数位4位,小数位2位
    SQL> select sal from emp;     SAL
    --------
      800.00
     1600.00
     1250.00
     2975.00
     1250.00
     2850.00
     2450.00
     3000.00
     5000.00
     1500.00
     1100.00     SAL
    --------
      950.00
     3000.00
     1300.00
      

  3.   


    to_char(round(amount,2),'fm999,999.00')
      

  4.   


    DB2里面  round函数会出错。。
      

  5.   

    DB2中 round函数是会出错的