create or replace procedure kq_num2 is
begin
  declare
  v_insert_num number(18,0); 
 begin
update  plugs_mat t set t.sex = null,num2=null where sex = 400 ;
  v_insert_num := 600; 
  for i in 1 .. v_insert_num loop
   update plugs_mat set num2= trunc(dbms_random.value(1,101))
where status = 400 ;
  end loop;
  update plugs_mat t set t.sex = 400 where status=400 and num2<60 ;
end;end kq_num2;上面的过程,执行起来要2分钟左右,数据表的数据并不多,总共有22659但符合条件才不到1000条,为什么会这么慢,哪还可以优化,或者怎么样判断耗时耗在哪了
相关上的谓词索引已经建立了

解决方案 »

  1.   


    for i in 1 .. v_insert_num loop
       update plugs_mat set num2= trunc(dbms_random.value(1,101))
    where status = 400 ;
      end loop;你这句是什么意思,吧STATUS=400的所有记录更新600遍。
    如果num2上加了索引,那更新索引的时间也不短。
      

  2.   

    update 完了 要 commit; 不知道是不是这个问题 
      

  3.   

    -- plugs_mat 表有主键吗?-- 如果有主键,就不需要循环更新!
      

  4.   

    -- 其实你环境里面的更新语句,只有最后一次的更新会生效,-- 前面你一直在让程序... 做无用功!-- 呵呵,倒不如:去掉循环,直接:
       update plugs_mat set num2= trunc(dbms_random.value(1,101))
    where status = 400 ;
      

  5.   

     --你的里面这个for i in 1 .. v_insert_num loop 就循环600次 我直接在你的改了下看看create or replace procedure kq_num2 is
    v_insert_num number(18,0); 
     begin
    update  plugs_mat t set t.sex = null,num2=null where sex = 400 ;
      v_insert_num := 600; 
      update plugs_mat set num2= trunc(dbms_random.value(1,101))
      where status = 400 ;
      update plugs_mat t set t.sex = 400 where status=400 and num2<60 ;
    end;
      

  6.   

    如果去掉循环,num2的值就一样了,我要得效果是num2是随机的
      

  7.   

    对plugs_mat表的sex,status加上索引试试