假如 一个表中的字段的类型是 varchar2(20) 内容为120.00000000000000000000000 为了记录简单 我只需要记录为120.00但是 现在表中都有内容了,而且上万条,请问怎么给一个简单的方法 把120。00000000000000000000000改变为120.00

解决方案 »

  1.   

    update table  set  table_column=substr(table_column,1,6);
      

  2.   


    给你一个样例吧,就是截取小数点“.”后面2个数字吧,可以这样截取的:
    select 
      substr('120.00000000000000000000000',0,instr('120.00000000000000000000000','.',1,1)+2)
    from dual 
      

  3.   

    查看一下:(看看是不是你想要的)
    select substr(table_column,0,instr(table_column,'.')+2) from table;
    更新:
    update table  set  table_column=substr(table_column,0,instr(table_column,'.')+2);
      

  4.   

    update tablename
    set c1=  case when instr(c1,'.',1,1)>0 then substr(c1,0,instr(c1,'.',1,1)+2)
                  else c1 end;如果有小数点,就update,截取小数点后面2位,否则不截取、。
      

  5.   

    超级晕菜还要考虑四舍五入吧对你的案例而言就是:update table  test
    set  table_column=round(field_name,2);
      

  6.   

    SQL> select * from t;COL
    ----------------------------------------
    120.00000000000000000000000
    20.00000000000000000000000SQL> update t set col=to_char(to_number(col),'99999.99');2 rows updated.SQL> select * from t;COL
    ----------------------------------------
       120.00
        20.00SQL>