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 分批插入 分批删除的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-11国产医疗级心电ECG采集处理模块
- 2025-01-10Rakuten 乐天积分系统从 Cassandra 到 TiDB 的选型与实战
- 2025-01-09CMS内容管理系统是什么?如何选择适合你的平台?
- 2025-01-08CCPM如何缩短项目周期并降低风险?
- 2025-01-08Omnivore 替代品 Readeck 安装与使用教程
- 2025-01-07Cursor 收费太贵?3分钟教你接入超低价 DeepSeek-V3,代码质量逼近 Claude 3.5
- 2025-01-06PingCAP 连续两年入选 Gartner 云数据库管理系统魔力象限“荣誉提及”
- 2025-01-05Easysearch 可搜索快照功能,看这篇就够了
- 2025-01-04BOT+EPC模式在基础设施项目中的应用与优势
- 2025-01-03用LangChain构建会检索和搜索的智能聊天机器人指南