PROCEDURE BACKUP_PROCEDURE (P_ERRORCODE OUT NUMBER, P_ERRORMSG OUT VARCHAR2)
AS
CURSOR C_HEADERS
IS
SELECT *
FROM APPS.HQ_HEADERS
WHERE TRANSACTION_DATE < TRUNC (ADD_MONTHS (SYSDATE, -3));
CURSOR C_LINES
IS
SELECT L.*
FROM APPS.HQ_HEADERS H, APPS.HQ_LINES L
WHERE H.AL_HEADER_ID = L.AL_HEADER_ID
AND H.TRANSACTION_DATE < TRUNC (ADD_MONTHS (SYSDATE, -3));
TYPE AL_HEADERS IS TABLE OF APPS.HQ_HEADERS%ROWTYPE
INDEX BY PLS_INTEGER;
X_AL_HEADERS AL_HEADERS;
TYPE AL_LINES IS TABLE OF APPS.HQ_LINES%ROWTYPE
INDEX BY PLS_INTEGER;
X_AL_LINES AL_LINES;
X_LIMIT_IN NUMBER := 200;
BEGIN
SAVEPOINT BACKUP_RECORDS;
OPEN C_HEADERS;
LOOP
FETCH C_HEADERS
BULK COLLECT INTO X_AL_HEADERS LIMIT X_LIMIT_IN;
FORALL X IN X_AL_HEADERS.FIRST .. X_AL_HEADERS.LAST
INSERT INTO APPS.HQ_HEADERS_HIST
VALUES X_AL_HEADERS (X);
EXIT WHEN X_AL_HEADERS.COUNT < X_LIMIT_IN;
END LOOP;
CLOSE C_HEADERS;
OPEN C_LINES;
LOOP
FETCH C_LINES
BULK COLLECT INTO X_AL_LINES LIMIT X_LIMIT_IN;
FORALL X IN X_AL_LINES.FIRST .. X_AL_LINES.LAST
INSERT INTO APPS.HQ_LINES_HIST
VALUES X_AL_LINES (X);
EXIT WHEN X_AL_LINES.COUNT < X_LIMIT_IN;
END LOOP;
CLOSE C_LINES;
COMMIT;
P_ERRORCODE := 0;
EXCEPTION
WHEN OTHERS
THEN
ROLLBACK TO BACKUP_RECORDS;
P_ERRORCODE := 2;
END;
No comments:
Post a Comment