两个表 tb1,tb2
结构如下
tb1:
id number(6) not null,
pcs number(9) null,
xzqh number(6) null,
。。tb2:
id number(6) not null,
xzqh number(6) null,
tx Blob null,
。。两个表的id,xzqh相互对应,即tb1中每条记录在tb2中有一条记录存在或没有对应记录,但它们没有父子关系.表记录数6000万,现从tb2中删除20万数据,满足的条件如下:
1, xzqh= 100000
2, tb1中的pcs最后三位 在100-199之间.我写了以下语句:
for i in 1..40
loop
delete from tb2 where xzqh=100000 and
id in (select id from tb1 where xzqh=100000 and
substr(to_char(pcs),7,3)>=100 and
substr(to_char(pcs),7,3)<=199) and rownum<=5000;
commit;
end loop;假设已在substr(to_char(pcs),7,3)上建基于函数的索引(Function-Based Index)
现在的问题是 “in”操作符查询效率太慢!!!
请问各位,能否不用“in”. 或者另有更好的实现方式??
结构如下
tb1:
id number(6) not null,
pcs number(9) null,
xzqh number(6) null,
。。tb2:
id number(6) not null,
xzqh number(6) null,
tx Blob null,
。。两个表的id,xzqh相互对应,即tb1中每条记录在tb2中有一条记录存在或没有对应记录,但它们没有父子关系.表记录数6000万,现从tb2中删除20万数据,满足的条件如下:
1, xzqh= 100000
2, tb1中的pcs最后三位 在100-199之间.我写了以下语句:
for i in 1..40
loop
delete from tb2 where xzqh=100000 and
id in (select id from tb1 where xzqh=100000 and
substr(to_char(pcs),7,3)>=100 and
substr(to_char(pcs),7,3)<=199) and rownum<=5000;
commit;
end loop;假设已在substr(to_char(pcs),7,3)上建基于函数的索引(Function-Based Index)
现在的问题是 “in”操作符查询效率太慢!!!
请问各位,能否不用“in”. 或者另有更好的实现方式??
解决方案 »
- SQL语句
- pl/sql看不到job,为什么?
- 谁有oracle 存储过程和触发器的入门教程?
- 定义游标的select语句中可以有group by 吗 ?
- 求《Oracle数据库管理员技术指南》的下载地址???
- 多用户并发时,似乎是插入错!
- select seq_aa.nextval from dual;我在jdbc里如何把该直取回并变成long型?
- oracle中,为什么有大字段varchar(4000)时,查询速度会很慢???
- 安装时,主机名,端口号,服务名怎么填?
- oracle如何快速异地远程备份?
- 在线求救!Help!!!!Oracle 数据装入的问题(imp)????
- 8.1.5上建基于函数的索引(FBI)失败??
loop
delete from tb2 where xzqh=100000 and
id = (select id from tb1 where xzqh=100000 and
substr(to_char(pcs),7,3)>=100 and
substr(to_char(pcs),7,3)<=199) and rownum<=5000;
commit;
end loop;
where szqh=100000
and exists (select 'x'
from tb1
where tb1.id=tb2.id
and tb1.szqh=tb2.szqh
and substr(to_char(tb1.pcs),7,3)>=100
and substr(to_char(tb1.pcs),7,3)<=199)
and rownum<=5000;
create or replace view
view1 as
select id,
from tb1
where szqh=100000 and
substr(to_char(pcs),7,3) between '100' and '199' and
rownum<=5000;
2﹑step2:
delete from tb2
where szqh=100000 and
id in (select id from view1);
3﹑step3:
如果step2還是很慢的話請在sqlplus中采取這一種方式試一下﹕
var i number;
declare cursor a is
select id from view1;
begin
:i:=0;
for c in a loop
delete from tb2
where id=c.id and szqh=100000 ;
:i:=:i+1;
if :i>=100 then
commit;
:i:=0;
end if;
end loop;
commit;
end ;
/