oracle优化存储过程,使其提高效率

oracle优化存储过程,使其提高效率

问题描述:

说明:优化这个存储过程,T_text 数据为100多条;T_text_standard 200万条数据,现在这个存储过程严重影响效率,请大神帮我优化一下,或这用普通sql写出来
T_text 表结构 ,ID,xm,ygid ,zh , lx ,time,status ;

T_text_standard 表结构 xm,ygid ,zh ;

create or replace procedure PROC_text (inputterm in varchar2,return_value out varchar2) is

cursor bm_cursor
is select * from T_text where time=inputterm;

datarow bm_cursor%rowtype;--数据每行
data_count number; --数据数量

-- inputterm 日期
--status 状态 0删除 1.正常
--ygid 员工号
-- lx 类型 01:开户 02:变更 03:销户
-- zh 账户

--T_text_standard 标准表
--T_text 基础表

begin
return_value:='yes';

--删除不是当前日期的数据

for datarow in bm_cursor loop
update T_text t set t.status='0' where ygid=datarow.ygid and zh=datarow.zh and time<>inputterm;
commit;

--查询标准库
   --循环查询标准库信息
   execute immediate'select count(1) from T_text_standard where  ygid=  '''||datarow.ygid||'''and zh='''||datarow.zh ||'''' into data_count;

  --如果查询数量>0 但不销户,修改类型为变更
   if data_count >0 then
        execute immediate 'update T_text set lx=''02'' where ygid='''||datarow.ygid||'''and zh='''||datarow.zh||'''and lx<>''03''';
      commit;
      else
      --如果查询数量其他 但不销户,修改类型为开户,
        execute immediate 'update T_text set lx=''01'' where ygid='''||datarow.ygid||'''and zh='''||datarow.zh||'''and lx<>''03''';
      commit;

      --如果标准库中不存销户信息,则复制这条信息为开户信息
         if datarow.lx='03' then
          execute immediate' insert into T_text
               select ''012'', xm, ygid,lx,zh,status ,time
           from T_text where khyhdm='''||datarow.id||'''';
          commit;
         end if;

    end if;


end loop;

end PROC_text;