create or replace procedure kq_num2 is
begin
  declare
  v_insert_num number(18,0);  -- 你想插入记录的条数
begin
update  plugs_mat t set t.sex = null where sex = 400  ;
  v_insert_num := 600; -- 比如:插入100条记录行
  for i in 1 .. v_insert_num loop
   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 loop;
end;end kq_num2;相关谓词上索引已建好 ,sex 是number 类型,status 也是nubmer ,num2也是numberplugs_mat 表总记录才 16572
status 为400 才有509
执行上面的过程却要240秒,还可以怎么优化上面的过程吗 

解决方案 »

  1.   

    把update更新放到loop 循环外,性能提高了不了,但还是要110秒
    还能怎么优化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; -- 比如:插入100条记录行
      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.   

    索引建好create or replace procedure kq_num2 is
    begin
      declare
      v_insert_num number(18,0);  -- 你想插入记录的条数
    begin
    update  plugs_mat t set t.sex = null where sex = 400  ;
    commit;
      v_insert_num := 600; -- 比如:插入100条记录行
      for i in 1 .. v_insert_num loop
       update plugs_mat set num2= trunc(dbms_random.value(1,101))
    where status = 400 ;
    commit;
    update plugs_mat t set t.sex = 400 where status=400 and num2<60 ;
    commit;
      end loop;
    end;end kq_num2;加commit之后运行一下,试试。
    我有一个问题:一、
      for i in 1 .. v_insert_num loop
         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 loop;
    执行一个和循环执行600次,一样呀.我没太理解。
      

  3.   

      for i in 1 .. v_insert_num loop
       update plugs_mat set num2= trunc(dbms_random.value(1,101))
    where status = 400 ;  end loop;
    你这个放到循环里面也是一样的呀。执行1次和600次效果一样的呀。