CREATE OR REPLACE PROCEDURE archive_emp
(maxarchiverow number) IS /* 定義歸檔的記錄數*/
v_crowid archive_rows
intLoop number; /* 記數器*/
v_primarykey archive_rows
CURSOR C_ARCH_EMP IS
SELECT * FROM ARCHIVE_ROWS; /* 創建游標*/
BEGIN
DELETE FROM ARCHIVE_ROWS; /*先清空臨時表*/
COMMIT;
INSERT INTO ARCHIVE_ROWS
SELECT ROWID
COMMIT; /*將基表中指定行數的rowid插入臨時表*/
INTLOOP:=
OPEN C_ARCH_EMP;
LOOP FETCH C_ARCH_EMP INTO V_CROWID
INTLOOP:=INTLOOP+
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
THEN
INSERT INTO ARCHIVE_LOG VALUES(
COMMIT;
END IF;
END LOOP;
END ARCHIVE_EMP;
/
[
From:http://tw.wingwit.com/Article/program/SQL/201311/16144.html