以下是我写的关于删除一个表中某些记录的过程
create or replace procedure Del_pur_order
(
p_tablename in varchar2, --表名
p_condition in varchar2, --条件
p_count in number --每次删除条数
)
as
pragma autonomous_transaction;
n_delete number:=0;
Asql varchar2(100);
begin
while 1=1 loop
n_delete:=p_count;
EXECUTE IMMEDIATE
'delete from '||p_tablename||' where '||p_condition||' and rownum <=:1'
USING p_count;-- Asql:= 'delete from'''||p_tablename||''' where'''|| p_condition||''' and rownum<=''';--||p_count||'''';
dbms_output.put_line(Asql);
if sql%notfound then
exit;
else
n_delete := n_delete + sql%rowcount;
end if;
commit;
end loop;
commit;
end Del_pur_order;
经过测试发现没有比直接用delete from||p_tablename|| where|| p_condition删除快.这是什么原因,有没有那位大哥有更好的删除办法.能使删除的速度更快.
create or replace procedure Del_pur_order
(
p_tablename in varchar2, --表名
p_condition in varchar2, --条件
p_count in number --每次删除条数
)
as
pragma autonomous_transaction;
n_delete number:=0;
Asql varchar2(100);
begin
while 1=1 loop
n_delete:=p_count;
EXECUTE IMMEDIATE
'delete from '||p_tablename||' where '||p_condition||' and rownum <=:1'
USING p_count;-- Asql:= 'delete from'''||p_tablename||''' where'''|| p_condition||''' and rownum<=''';--||p_count||'''';
dbms_output.put_line(Asql);
if sql%notfound then
exit;
else
n_delete := n_delete + sql%rowcount;
end if;
commit;
end loop;
commit;
end Del_pur_order;
经过测试发现没有比直接用delete from||p_tablename|| where|| p_condition删除快.这是什么原因,有没有那位大哥有更好的删除办法.能使删除的速度更快.
解决方案 »
- oracle刚学。。
- 在线等"HH84"是select中没有的,只到83,怎么会跑出来呢,程序是部署在resin3.1
- 增加了on delete cascade级联删除 ,现在想撤销如何做?
- sql语句子查询转换
- 调用过程出错,大家来看看!
- 请问如何在SQL脚本文件中,写编译某一函数的语句?
- 三个问题:
- 在树形结构中,怎么样用一个SQL语句选出当前项的所有子项???
- 急!oracle 9i导出的数据如何导入8i中?
- 有什么工具做SQL SERVER与Oracle之间转换数据,可以直接把sql server的text类型转换成Oracle的CLOB类型
- 关于建立索引失败(顶者有分)
- 用Drop table(100000条记录)后磁盘可用空间没增大?怎样真正删除,以增大磁盘可用空间?
可以先考虑优化相应的 select 语句。
delete xx where id= xx+i;
--或者其他条件,由i循环
commit;
next
--这样的好处:减少redo的空间,每次提交 清空缓冲区的reundo
大量的数据要分批的删除,这样速度快