oracle 分批插入 分批删除
2021/9/12 19:05:05
本文主要是介绍oracle 分批插入 分批删除,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
create or replace procedure insbigtab ( p_TableName in varchar2, p_Condition in varchar2, p_Count in number, p_insettab in varchar2 ) is Type v_rowid is table of varchar2(100) index by binary_integer; type type_cursor is ref cursor; v_cur type_cursor ; var_rowid v_rowid; sql1 varchar2(1000); tb varchar2(1000); co varchar2(1000); pc number; pinst varchar2(1000); begin tb:=p_TableName; co:=p_Condition; pc:=p_Count; pinst:=p_insettab; sql1:='select ROWID from '||tb||' where '||co; open v_cur for sql1 ; loop fetch v_cur bulk collect into var_rowid limit pc; forall i in 1 .. var_rowid.count execute immediate 'insert into '||pinst||' select * from '||tb||' where ROWID = :rn ' USING var_rowid(i); commit; dbms_lock.sleep(3); exit when v_cur%NOTFOUND or v_cur%NOTFOUND is null; END LOOP ; close v_cur; end;
exec yz.insbigtab('yz.t1','object_id>5000',10000,'yz.t2');
create or replace procedure delbigtab
(
p_TableName in varchar2,
p_Condition in varchar2,
p_Count in varchar2
)
as
pragma autonomous_transaction;
n_delete number:=0;
begin
while 1=1 loop
EXECUTE IMMEDIATE
'delete from '||p_TableName||' where '||p_Condition||' and rownum <= :rn'
USING p_Count;
if SQL%NOTFOUND then
exit;
else
n_delete:=n_delete + SQL%ROWCOUNT;
end if;
commit;
dbms_lock.sleep(3);
end loop;
commit;
DBMS_OUTPUT.PUT_LINE('Finished!');
DBMS_OUTPUT.PUT_LINE('Totally '||to_char(n_delete)||' records deleted!');
end;
exec yz.delbigtab('yz.t1','object_id>5000','10000');
delbigtab
这篇关于oracle 分批插入 分批删除的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-29Excel中实现拖动排序的简易教程
- 2024-11-29如何在Excel中使用拖动排序功能
- 2024-11-28阿里云 ECS课程:新手入门教程
- 2024-11-27Excel中实现拖动排序的简单教程
- 2024-11-27Rocket消息队列资料:新手入门指南
- 2024-11-27rocket消息队资料详解与入门指南
- 2024-11-27RocketMQ底层原理资料详解入门教程
- 2024-11-27RocketMQ项目开发资料:新手入门教程
- 2024-11-27RocketMQ项目开发资料详解
- 2024-11-27RocketMQ消息中间件资料入门教程