现在有一个表,有上百万的数据,其中有一个AGE字段,我现在要一次性把这个表的AGE字段内容全部更新为18,如果只是单独地用UPDATE命令,一般情况下肯定会报错,请问有什么好的办法???谢谢!!!

解决方案 »

  1.   

    先导出到一个测试库,把它update后,再导入
    速度上比较可行
      

  2.   

    内存多大?是你的临时表空间太小,回滚空间太小?
    把错误号码报出来大家看看,UPDATE命令本身无错!
      

  3.   


     1. 设置一个私有的回滚段,可以设置大一些.
        SET TRANSACTION USE ROLLBACK SEGMENT RBSNAME;
        update TableName set ...
        COMMIT;   缺点:运行速度慢,并且会产生大量重做日志 2. 启动一个事务,批量更新    缺点: 速度不会快很多,但安全性有保证 3. 对表进行分区,然后在每个分区内执行更新操作(推荐)    partition the data, do a parallel update.  Each partition
        will use its own  rollback segment, each will run in parallel.
      

  4.   

    设置条件 分批update 也可以阿 但是 就是速度不会很快 每一次还要检索
    update a set aeg=18  where aeg=20 数据大了 本身就没有什么好方法 导入 导出 一次就要很长时间
      

  5.   

    If I had to update millions of records I would probably opt to NOT update.I would more likely do:CREATE TABLE new_table as select <do the update "here"> from old_table;index new_table
    grant on new table
    add constraints on new_table
    etc on new_tabledrop table old_table
    rename new_table to old_table;
    you can do that using parallel query, with nologging on most operations 
    generating very little redo and no undo at all -- in a fraction of the time it 
    would take to update the data.
      

  6.   

    也许可以试一下这个方法:
    loop
    update table
    set age=18
    where age <> 18
    and rownum < 100
    ;
    commit;
    if sql%rowcount = 0 then break;
    end loop
      

  7.   

    whan1234(小韩) 的方法很酷!
      

  8.   


      whan1234(小韩) 的方法就是批量更新.
      如果让我选择,我会考虑 l2g32003的方法.
      

  9.   

    谢谢大家,在此我测试了 l2g32003(leeshow)的方法,60多万条的数据的表,我用了两三分钟就搞定了,所以我感觉在这种情况下我会选用 l2g32003(leeshow)方法。这是我的个人的看法希望大家还有什么更好的方法!!!
      

  10.   

    to l2g32003(leeshow):It's a good idea!
    up
    60多万条记录直接update也不会需要多少回滚段呀!!而且update占用回滚段又不多。
    insert,update,delete占用回滚段大小是依次增加大的。
    因为insert操作中回滚段中记录新记录的rowid,update时记录旧的更改过的字段值,而delete则不一样了,它要记录删除的记录的所有字段的信息。
      

  11.   

    方案一
    1.create table test(c1,...,age,...,cn) nologging
    as
    select c1,...,18,...cn2.建立索引,主键3.删除原来的表(drop table)4.表改名(rename)方案二
    1.删除索引再更新2.重建索引