分类:
2008-10-16 19:09:36
CREATE OR REPLACE PROCEDURE archive_emp
(maxarchiverow number) IS /* 定义归档的记录数*/
v_crowid archive_rows.crowid%type; /* 存放基表的rowid*/
intLoop number; /* 记数器*/
v_primarykey archive_rows.PRIMARYKEY%type;
CURSOR C_ARCH_EMP IS
SELECT * FROM ARCHIVE_ROWS; /* 创建游标*/
BEGIN
DELETE FROM ARCHIVE_ROWS; /*先清空临时表*/
COMMIT;
INSERT INTO ARCHIVE_ROWS
SELECT ROWID,'' FROM EMP_B WHERE ROWNUM < MAXARCHIVEROW;
COMMIT; /*将基表中指定行数的rowid插入临时表*/
INTLOOP:=0;
OPEN C_ARCH_EMP;
LOOP FETCH C_ARCH_EMP INTO V_CROWID,V_PRIMARYKEY;
INTLOOP:=INTLOOP+1;
EXIT WHEN C_ARCH_EMP%NOTFOUND;
INSERT INTO EMP_ARCHIVE SELECT * FROM EMP_B WHERE ROWID=V_CROWID;
/*根据rowid,将数值插入到归档表中*/
COMMIT;
DELETE FROM EMP_B WHERE ROWID=V_CROWID; /*将基表已归档数据删除*/
COMMIT;
IF MOD(INTLOOP,200)=0 /*以200行为界记录归档情况*/
THEN
INSERT INTO ARCHIVE_LOG VALUES('EMP_B',INTLOOP,SYSDATE);
COMMIT;
END IF;
END LOOP;
END ARCHIVE_EMP;