我想批量更新表中的数据,,,应为表中有几千万的数据,,,请问下面SQL语句有问题吗?    
还有比这个更快的SQL语句吗?        update
(
   select
   a.exam_result_id A1,
   c.exam_result_id B1
   from 
   the_d_exam_result_item a 
   join the_d_exam_result_frame b on a.exam_result_item_id = b.exam_result_item_id
   join the_d_exam_result c on b.exam_result_frame_id = c.exam_result_frame_id
)
set A1 = B1时间常了报 ORA01089 错误,, 不知道是我SQL原因还是别人重启数据库了比如我这个SQL语句执行了1个小时,后来报错,那这1个小时有数据被更新吗???????????

解决方案 »

  1.   

    你这个sql怎么能引起数据库关闭了,把心放到肚子里。但是至于这个一个小时的数据被不被更新,更新是一定的,但是没有commit,数据库关闭的时候默认回滚了。
    数据库起来之后你再执行一次呗。
      

  2.   

    没见过这种更新语句,按本人的理解 update 语法,不能像你这么写。另执行了一个小时,报错,说明错误卡住,并不是说有数据被更新了,就算有数据更新,一旦错误而且无提交事务语句,数据会回滚不会提交。
      

  3.   


    --你的寫法更新出錯了,是不會更新到數據庫的
    --幫你改了點,試下
    create or replace procedure proc_t
    is
    begin
    update
    (
      select
      a.exam_result_id A1,
      c.exam_result_id B1
      from  
      the_d_exam_result_item a  
      join the_d_exam_result_frame b on a.exam_result_item_id = b.exam_result_item_id
      join the_d_exam_result c on b.exam_result_frame_id = c.exam_result_frame_id
      where a.exam_result_id<>c.exam_result_id and rownum<10000--每次更新多少自已指定
    )
    set A1 = B1;
    commit;
    end;
    /
    --執行更新
    declare 
    v_i int := 0;
    begin
    loop
    exit when v_i>10;--更新多少次自已指定吧
    proc_t;
    v_i := v_i+1;
    end loop;
    end;
    /