求大神帮忙看看,这个存储存在运行的时候很慢,希望得到解决

mj845573397 2017-08-04 05:30:59
create or replace procedure pro_license is
num number;
v_sql varchar2(100);
v_unid license_jh.xk_id%type;
cursor temp_cursor is
select xk_id from license_jh;
begin
open temp_cursor;
loop
fetch temp_cursor
into v_unid;
exit when temp_cursor%notfound;
select count(*) into num from license where unid = '' || v_unid || '';

if num >= 1 then
update license a
set (a.AREACODE,
a.XZXKWS_CODE,
a.XZXKWS_NAME,
a.BXZXK_NAME,
a.BXZXK_LEGALMAN,
a.XZXK_DATE,
a.XZXK_JZQ,
a.CTIME,
a.DEPT,
a.PARENTDEPT,
a.PTIME,
a.XZXK_NR,
a.XZXK_JG,
a.DATAVERSION,
a.XZXK_GKLX,
a.XZXK_STATE,
a.DELETEFLAG,
a.STATUS,
a.XZXK_SPLB,
a.CNAME,
a.PNAME,
a.XZXK_REGINNAME,
a.XZXK_ORGNAME,
a.XZXK_ORGCODE,
a.BXZXK_TYPE) =

(select b.AREACODE,
'空',
b.xk_xmmc,
b.xk_xdr,
b.xk_fr,
to_char(to_date(xk_jdrq,'yyyy-Mm-dd HH24:Mi:SS'),'yyyy-mm-dd'),
b.xk_jzq,
b.sjc,
b.xzxk_orgcode,
substr(b.xzxk_orgcode, 1, 6),
b.sjc,
b.xk_nr,
b.xzxk_orgname,
b.bbh,
0,
0,
0,
1,
'普通',
b.n || 'admin',
b.n || 'admin',
e.name,
b.name,
b.n,
(case
when length(b.xk_xdr) <= 5 then
1
when length(b.xk_xdr) > 5 then
2
end)
from sys_department e,
(select c.parentid,
d.*,
c.name,
c.areacode || c.deptcode as n
from license_jh d, sys_department c
where d.xzxk_orgcode = c.id
and bbh = (select max(bbh)
from license_jh f
where f.xk_id = d.xk_id)) b
where e.id = b.parentid
and a.unid = b.xk_id)
where exists (select 1
from sys_department e,
(select c.parentid,
d.*,
c.name,
c.areacode || c.deptcode as n
from license_jh d, sys_department c
where d.xzxk_orgcode = c.id
and bbh = (select max(bbh)
from license_jh f
where f.xk_id = d.xk_id)) b
where e.id = b.parentid
and a.unid = b.xk_id);
commit;
else
insert into license a
(a.unid,
a.AREACODE,
a.XZXKWS_CODE,
a.XZXKWS_NAME,
a.BXZXK_NAME,
a.BXZXK_LEGALMAN,
a.XZXK_DATE,
a.XZXK_JZQ,
a.CTIME,
a.DEPT,
a.PARENTDEPT,
a.PTIME,
a.XZXK_NR,
a.XZXK_JG,
a.DATAVERSION,
a.XZXK_GKLX,
a.XZXK_STATE,
a.DELETEFLAG,
a.STATUS,
a.XZXK_SPLB,
a.CNAME,
a.PNAME,
a.XZXK_REGINNAME,
a.XZXK_ORGNAME,
a.XZXK_ORGCODE,
a.BXZXK_TYPE)

select b.xk_id,
b.AREACODE,
'空',
b.xk_xmmc,
b.xk_xdr,
b.xk_fr,
to_char(to_date(xk_jdrq,'yyyy-Mm-dd HH24:Mi:SS'),'yyyy-mm-dd'),
b.xk_jzq,
b.sjc,
b.xzxk_orgcode,
substr(b.xzxk_orgcode, 1, 6),
b.sjc,
b.xk_nr,
b.xzxk_orgname,
b.bbh,
0,
0,
0,
1,
'普通',
b.n || 'admin',
b.n || 'admin',
e.name,
b.name,
b.n,
(case
when length(b.xk_xdr) <= 5 then
1
when length(b.xk_xdr) > 5 then
2
end)
from sys_department e,
(select c.parentid,
d.*,
c.name,
c.areacode || c.deptcode as n
from license_jh d, sys_department c
where d.xzxk_orgcode = c.id
and bbh = (select max(bbh)
from license_jh f
where f.xk_id = d.xk_id)) b
where e.id = b.parentid
and b.xk_id = v_unid;
commit;
end if;
end loop;
close temp_cursor;
end;

把单个update和insert拿出来运行,速度还是挺快的,在这歌存储里面裕兴就很慢,而且会产生大量的归档日志,以至于归档空间不够用,希望大神们帮忙看看,怎样优化才能加快运行速度,以及减少归档日志的产生
...全文
267 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mj845573397 2017-08-07
  • 打赏
  • 举报
回复
我这个主要做的事插入更新,不是单独的更新
mayanzs 2017-08-07
  • 打赏
  • 举报
回复
这种又是update,又是insert的,建议改用效率更高的merge语句,速度要快很多。另:在必要的字段上建立索引
卖水果的net 2017-08-04
  • 打赏
  • 举报
回复
这是一个循环操作,建议改成批量更新的方式。

17,082

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧