首页 > 数据库 > 数据库开发技术 > 删除100W行数据的方法
找到了两种方法删除100W行的数据
[@more@]1, ------------------
declare
v_n number :=0;
begin
if v_n < 100万 then
delete from datta where csid=41 and rownum<2001;
v_n := v_n+2000;
commit;
end if;
delete from datta where csid=41;
commit;
end;
/
2, -------------
1.根据用户所提需求过滤需要删除的源数据,create 临时表 as select rowid rid from 需要删除的表 where 删除条件。
2.使用pl/sql block来删除数据,这样能保证及时递交,防止lock过多的行导致系统负载增加。这里需要注意commit的频率,一般为更新100条记录commit一次。
create table temp_del表名_040803 as
select rowid rid from 要删除的表 where ......
declare
execrow number;
begin
execrow:=1;
for i in 1..需要更新的记录数/100(取整) loop
delete 要删除的表
where rowid in(select rid from temp_del表名_040803 where rownum<100);
delete from temp_del表名_040803 where rownum<100;
commit;
end loop;
end;
/
记得再建一张临时表保存要删除的内容已备回滚。这样根据rowid来删除的话效率会比较高。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/348136/viewspace-929411/ ,如需转载,请注明出处,否则将追究法律责任。