begin
  for i in 1..500 loop
  update  cj_full_detail_mat t set t.random=dbms_random.value(0,10000)
where t.status=40
and t.random is null
and rownum=1;
end loop
commit;
end 运行这个要13s
 如果是改成for i in 1..1000 loop
要23s换成for i in 1..2000 loop要33s表的记录总共才5万
dbms_random.value怎么这么慢呢,有什么样方法可以加快点

解决方案 »

  1.   

    SQL> begin
      2    for i in 1..500 loop
      3    update  cj_full_detail_mat t set t.random=dbms_random.value(0,10000)
      4  where t.random is null
      5  and rownum=1;
      6  end loop
      7  commit;
      8  end
      9  ;
     10  /
     
    PL/SQL procedure successfully completed
     
    Executed in 0.109 seconds如果status项包含的值不多的话,加上位图索引试一试
      

  2.   

    上贴有人答曰“Mo Si Ni”
      

  3.   

    update  cj_full_detail_mat t set t.random=dbms_random.value(0,10000)
    where t.status=40
    and t.random is null
    and rownum<=500;
      

  4.   

    begin
      for i in 1..100 loop
      update  cj_full_detail_mat t set t.random=dbms_random.value(0,10000)
    where t.status=40 and t.random is null and rownum<500;
    end loop
    if mod(i,1000)=0 then
    commit;
    end if;
    end ;
      

  5.   


    你这样做,500行的random 都一样的了,我要得效果是每条记录的random都要很随机