删除大数量的表中数据之存储过程模板
来源:互联网 发布:苏联暴行知乎 编辑:程序博客网 时间:2024/05/20 18:20
create or replace procedure large_table_clean_template(var_tablename varchar2,var_condition varchar2) astype type_rowid_array is table of rowid;type ref_cursor is ref cursor;rowid_array type_rowid_array;cur_rowids ref_cursor;select_sqlText varchar2(500);i_arraysize integer := 100;i_number integer;beginselect count(1) into i_number from user_tables where table_name=upper(var_tablename);if(i_number = 0) thenreturn;end if;select_sqlText := 'select rowid from ' || var_tablename || ' where ' || var_condition;open cur_rowids for select_sqlText;loopfetch cur_rowids bulk collect into rowid_array limit i_arraysize;forall i in 1..rowid_array.countexecute immediate 'delete from ' || var_tablename || ' where rowid=:1' using rowid_array(i);if(mod(cur_rowids%rowcount,20000)=0) thencommit;end if;exit when cur_rowids%notfound;end loop;commit;if(cur_rowids%isopen) thenclose cur_rowids;end if;exceptionwhen others thenrollback;if(cur_rowids%isopen) thenclose cur_rowids;end if;end;/
1、通过bulk collect减少loop处理的开销,使用Bulk Collect提高Oracle查询效率
Oracle8i中首次引入了Bulk Collect特性,该特性可以让我们在PL/SQL中能使用批查询,批查询在某些情况下能显著提高查询效率。
采用bulk collect可以将查询结果一次性地加载到collections中。
而不是通过cursor一条一条地处理。
可以在select into,fetch into,returning into语句使用bulk collect。
注意在使用bulk collect时,所有的into变量都必须是collections
2、forall与for的区别
for循环和forall循环的区别
阅读全文
1 0
- 删除大数量的表中数据之存储过程模板
- 删除大数量数据(oracle)
- 删除表中重复数据的存储过程(带参数的)
- SQL脚本--(通用存储过程)如何删除表中某个字段重复的数据
- SQL存储过程之删除指定表中所有索引
- 【ORACLE】删除表数据的存储过程backup.sql
- 用存储过程删除外键关联表的数据
- 删除多余数据行的存储过程
- 在存储过程中删除表的列
- sqlserver删除数据库中所有的表和存储过程
- 删除MSSQL中危险的存储过程
- 存储过程删除大量数据
- CYQ.Data 轻量数据层之路 使用篇五曲 MProc 存储过程与SQL(十六)
- 生成表中数据的sql语法的存储过程
- 简单的存储过程分页,删除多条记录的存储过程,存储过程中调用存储过程
- 根据表中数据生成insert语句的存储过程
- 根据表中数据生成insert语句的存储过程
- 根据表中数据生成insert语句的存储过程
- poj 2112 最大流求二分图匹配/二分搜索
- 读者写者问题
- The more, The Better HDU
- RabbitMQ系列教程之七:RabbitMQ的 C# 客户端 API 的简介
- 【C语言】查询算法
- 删除大数量的表中数据之存储过程模板
- Wormholes
- glib-The Main Event Loop
- 素数的一些逻辑题
- php-curd基类框架
- 兔子繁衍问题求解(阿里巴巴2017在线编程题)
- shell算法的使用
- 2017 Multi-University Training Contest
- 动态规划之背包问题——Java实现