sql分段处理删除大量数据
2007-11-11 12:17:42 来源:WEB开发网最近在QQ群里面,有人问起如何使用分段处理,竟然忘记如何操作,当时只是COPY一本书里的内容,只记得大致的步骤,先重新温习,以便记忆:
实现功能:
1.分段处理
2.拆分操作
3.批量绑定
--摘自《Oracle(大型网站数据库平台) 数据库性能优化》
CREATE OR REPLACE PROCEDURE del_hubel_SSF_forall
as
type ridArray is table of rowid index by binary_integer;
type dtArray is table of varchar2(50) index by binary_integer;
v_rowid ridArray;
v_mid_to_delete dtArray;
BEGIN
SELECT mid, rowid bulk_collect into v_mid_to_delete, v_rowid from temp_mid_hubei_bak WHERE ROWNUM<10001;
FORALL i in 1.. v_mid_to_delete.COUNT
DELETE FROM SSF WHERE mid=v_mid_to_delete(i);
--DBMS_OUTPUT_LINE(TO_CHAR(v_mid_to_delete.COUNT) || ' records deleted from hubei_SSF !!!');
FORALL i in i .. v_rowid.COUNT
DELETE FROM temp_mid_hubei_bak WHERE ROWID=v_rowid(i);
--DBMS_OUTPUT_LINE(TO_CHAR(v_mid_to_delete.COUNT) || ' records deleted from hubei_SSF !!!');
END;
CREATE OR REPLACE PROCEDURE exec_forall
(
p_RowCount in number, --Total need to delete rows count
p_ExeCount in number
)
AS
n_RowCount number:=0;
n_ExeTimes number:=0;
n_Delete number:=0;
BEGIN
n_RowCount :=p_RowCount;
WHILE n_RowCount>0
LOOP
EXECUTE IMMEDIATE 'begin del_hubei_SSF_forall; end;';
COMMIT;
IF n_RowCount>p_ExeCount THEN
n_RowCount:=n_RowCount-p_ExeCount;
n_ExeTime:=n_ExeTimes+1;
ELSE
n_ExeTimes :=n_ExeTimes+1;
n_Delete:=RowCount;
n_RowCount:=n_RowCount-p_ExeCount;
END IF;
--DBMS_OUTPUT_LINE('----------------' || TO_CHAR(n_ExeTimes) || '--------------');
n_delete :=n_delete+p_ExeCount*(n_ExeTimes-1);
END LOOP;
--DBMS_OUTPUT_LINE('Full Finished!!!');
--DBMS_OUTPUT_LINE('Totally' || TO_CHAR(n_delete) || 'records deleted. !!!');
END;
- ››SQL Server 2008 R2 下如何清理数据库日志文件
- ››sqlite 存取中文的解决方法
- ››SQL2005、2008、2000 清空删除日志
- ››SQL Server 2005和SQL Server 2000数据的相互导入...
- ››sql server 2008 在安装了活动目录以后无法启动服...
- ››sqlserver 每30分自动生成一次
- ››sqlite 数据库 对 BOOL型 数据的插入处理正确用法...
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
更多精彩
赞助商链接