llmclaughlin
Programmer
The below cursor works fine if I give it a date range of week to purge. When I give it a month of data to do it seems to hang up. Is there a way to streamline this?
PROCEDURE PurgeData(P_Date1 VARCHAR2,
P_Date2 VARCHAR2,
P_Cnt OUT INTEGER) IS
CURSOR L_Interlocks IS
SELECT *
FROM INTERLOCKS
WHERE TRUNC(DATE_RUN) >= TO_DATE(P_Date1,'MM/DD/YYYY')
AND TRUNC(DATE_RUN) <= TO_DATE(P_Date2,'MM/DD/YYYY')
ORDER BY INTERLOCK_ID;
CURSOR L_Results(C_ID IN NUMBER) IS
SELECT *
FROM TEST_RESULTS
WHERE INTERLOCK_ID = C_ID;
CURSOR L_Details(C_ResultID IN NUMBER) IS
SELECT *
FROM TEST_RESULTS_DETAILS
WHERE RESULT_ID = C_ResultID;
L_Cnt INTEGER := 0;
BEGIN
FOR R_Interlock IN L_Interlocks LOOP
INSERT INTO PURGED_INTERLOCKS (
INTERLOCK_ID, SERIAL_NUMBER, MODEL_NUMBER,
DATE_RUN, ORDER_ID, INTERLOCK_STATUS,
CCV_INTERLOCK_STATUS, TEST_NAME, PROCESSED)
VALUES (R_Interlock.Interlock_Id ,R_Interlock.Serial_Number ,R_Interlock.Model_Number ,R_Interlock.Date_Run
,R_Interlock.Order_Id ,R_Interlock.Interlock_Status ,R_Interlock.CCV_Interlock_Status
,R_Interlock.Test_Name ,R_Interlock.Processed);
FOR R_Results IN L_Results(R_Interlock.Interlock_Id) LOOP
INSERT INTO PURGED_TEST_RESULTS (
RESULT_ID, INTERLOCK_ID, PROGRAM_DESCRIPTION,
FAILURE_MESSAGE, OPERATOR, TEST_NUM,
STATION_ID, STATION_TYPE, DATE_TESTED,
TEST_STATUS, CYCLE_TIME)
VALUES (R_Results.Result_Id ,R_Interlock.Interlock_Id ,R_Results.Program_Description ,R_Results.Failure_Message
,R_Results.Operator ,R_Results.Test_Num ,R_Results.Station_Id
,R_Results.Station_Type ,R_Results.Date_Tested ,R_Results.Test_Status
,R_Results.Cycle_Time);
FOR R_Details IN L_Details(R_Results.Result_Id) LOOP
INSERT INTO PURGED_TEST_RESULTS_DETAILS (
DETAILS_ID, RESULT_ID, RESULT_NAME,
RESULT_VALUE, UNIT_MEASURE)
VALUES (R_Details.Details_id ,R_Results.Result_Id ,R_Details.Result_Name ,R_Details.Result_Value
,R_Details.Unit_Measure);
END LOOP;
DELETE FROM TEST_RESULTS
WHERE INTERLOCK_ID = R_Interlock.Interlock_Id;
DELETE FROM TEST_RESULTS_DETAILS
WHERE RESULT_ID = R_Results.Result_Id;
END LOOP;
DELETE FROM INTERLOCKS
WHERE INTERLOCK_ID = R_Interlock.Interlock_Id;
L_Cnt := L_Cnt + 1;
END LOOP;
P_Cnt := L_Cnt;
END PurgeData;
PROCEDURE PurgeData(P_Date1 VARCHAR2,
P_Date2 VARCHAR2,
P_Cnt OUT INTEGER) IS
CURSOR L_Interlocks IS
SELECT *
FROM INTERLOCKS
WHERE TRUNC(DATE_RUN) >= TO_DATE(P_Date1,'MM/DD/YYYY')
AND TRUNC(DATE_RUN) <= TO_DATE(P_Date2,'MM/DD/YYYY')
ORDER BY INTERLOCK_ID;
CURSOR L_Results(C_ID IN NUMBER) IS
SELECT *
FROM TEST_RESULTS
WHERE INTERLOCK_ID = C_ID;
CURSOR L_Details(C_ResultID IN NUMBER) IS
SELECT *
FROM TEST_RESULTS_DETAILS
WHERE RESULT_ID = C_ResultID;
L_Cnt INTEGER := 0;
BEGIN
FOR R_Interlock IN L_Interlocks LOOP
INSERT INTO PURGED_INTERLOCKS (
INTERLOCK_ID, SERIAL_NUMBER, MODEL_NUMBER,
DATE_RUN, ORDER_ID, INTERLOCK_STATUS,
CCV_INTERLOCK_STATUS, TEST_NAME, PROCESSED)
VALUES (R_Interlock.Interlock_Id ,R_Interlock.Serial_Number ,R_Interlock.Model_Number ,R_Interlock.Date_Run
,R_Interlock.Order_Id ,R_Interlock.Interlock_Status ,R_Interlock.CCV_Interlock_Status
,R_Interlock.Test_Name ,R_Interlock.Processed);
FOR R_Results IN L_Results(R_Interlock.Interlock_Id) LOOP
INSERT INTO PURGED_TEST_RESULTS (
RESULT_ID, INTERLOCK_ID, PROGRAM_DESCRIPTION,
FAILURE_MESSAGE, OPERATOR, TEST_NUM,
STATION_ID, STATION_TYPE, DATE_TESTED,
TEST_STATUS, CYCLE_TIME)
VALUES (R_Results.Result_Id ,R_Interlock.Interlock_Id ,R_Results.Program_Description ,R_Results.Failure_Message
,R_Results.Operator ,R_Results.Test_Num ,R_Results.Station_Id
,R_Results.Station_Type ,R_Results.Date_Tested ,R_Results.Test_Status
,R_Results.Cycle_Time);
FOR R_Details IN L_Details(R_Results.Result_Id) LOOP
INSERT INTO PURGED_TEST_RESULTS_DETAILS (
DETAILS_ID, RESULT_ID, RESULT_NAME,
RESULT_VALUE, UNIT_MEASURE)
VALUES (R_Details.Details_id ,R_Results.Result_Id ,R_Details.Result_Name ,R_Details.Result_Value
,R_Details.Unit_Measure);
END LOOP;
DELETE FROM TEST_RESULTS
WHERE INTERLOCK_ID = R_Interlock.Interlock_Id;
DELETE FROM TEST_RESULTS_DETAILS
WHERE RESULT_ID = R_Results.Result_Id;
END LOOP;
DELETE FROM INTERLOCKS
WHERE INTERLOCK_ID = R_Interlock.Interlock_Id;
L_Cnt := L_Cnt + 1;
END LOOP;
P_Cnt := L_Cnt;
END PurgeData;