oracle优化问题

heitaoc 2018-11-29 05:15:46
create or replace procedure test as
cursor carddata is select distinct g from cfsj;
str varchar2(100);
mark number(1);
begin

for x in carddata loop
str :='';
mark:=1;
for y in (select k from cfsj t where t.g = x.g) loop
if mark=1 then
str := y.k;
mark:=2;
end if;
str := str || ',' || y.k;
end loop;
delete from cfsj t1 where rowid !=(select max(rowid) from cfsj t2 where t1.g=t2.g) and t1.g=x.g;
update cfsj set k=str where g=x.g;
end loop;

end;

好慢哦
...全文
865 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
l19870910 2018-12-27
  • 打赏
  • 举报
回复
create or replace procedure test as
cursor carddata is select distinct g from cfsj;
str varchar2(100);
mark number(1);
begin

for x in carddata loop
str :='';
mark:=1;
for y in (select k from cfsj t where t.g = x.g) loop
if mark=1 then
str := y.k;
mark:=2;
end if;
str := str || ',' || y.k;
end loop;
delete from cfsj t1 where rowid !=(select max(rowid) from cfsj t2 where t1.g=t2.g) and t1.g=x.g;
update cfsj set k=str where g=x.g;
end loop;

end;
这个过程的意思是 只取cfsj 表里按g分组的最大rowid , 并将所有K列字段按分组拼接吧 是不是G列有空值?再或者表数据量过大,如果数据量过大 可以在使用临时表, 存放最大列rowid的行记录并加工数据 然后truncate原表, 最后将零时表数据插进实体表
Mricoo_周 2018-12-07
  • 打赏
  • 举报
回复
你的循环里面套循环,为什么不在外面的循环里面加一次commit呢,你这样的结果最终要有N多的undo占用,而且还费时间
heitaoc 2018-12-06
  • 打赏
  • 举报
回复
create table CFSJ
(
a VARCHAR2(1000),
b VARCHAR2(1000),
c VARCHAR2(1000),
d VARCHAR2(1000),
e VARCHAR2(1000),
f VARCHAR2(1000),
g VARCHAR2(1000),
h VARCHAR2(1000),
i VARCHAR2(1000),
j VARCHAR2(1000),
k VARCHAR2(1000),
l VARCHAR2(1000),
m VARCHAR2(1000),
n VARCHAR2(1000)
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
卖水果的net 2018-12-06
  • 打赏
  • 举报
回复
g 列加一个索引。
  • 打赏
  • 举报
回复
双重循环 本来就不快
卖水果的net 2018-11-30
  • 打赏
  • 举报
回复
表结构贴一下,包含索引情况。 只有这个过程,没什么判断依据。

17,082

社区成员

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

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