两个表 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”. 或者另有更好的实现方式??
解决方案 »
- 数据库创建向导问题( 提示输入 SYS和SYSTEM 密码,当是没有 确定按钮)
- 视图能否替代同义词???
- 导出表的时候,可以改表的名字吗?
- Rman 注销数据库时出错!!!
- oracle9i client连接服务器的问题
- 请教一个SQL语句的问题,如何进行两行数据对应相减
- oracle 家族树查询上级代理以及零售商排序问题出错了。。很有挑战性。。请水区的兄弟们解决!!在线等!
- 在oracle9i里怎么写计划任务?
- 安装oracle时出现错误
- 安装oracle19c的时候安装进度条到了80%又退回到0 接着提示已安装但有错误
- 在线求救!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 ;
/