Create or replace PROCEDURE CMPP_SUBMIT_REMOVE_PROCEDURE
Is
DEndTime date; -- each processing is a time point -- get the ID of the data to be processed
Cursor c_cmpp_submit (endTime date) is
Select id from cmpp_submit
Where (ih_process <> 'insert _ cmpp_submit 'and ih_process <> 'wait _ for_response ')
Or (ih_process = 'wait _ for_response 'and ih_retry <= 0 ))
And ih_timestamp <endTime and rownum <100001; iId number; -- id
ICount number; -- Counter
Begin -- dEndTime: = trunc (SYSDATE-1/288), 'mi'); -- obtains the processing time and processes the data five minutes ago.
DEndTime: = trunc (SYSDATE, 'mi'); -- Obtain the processing time point iCount: = 0; -- initialize the Count open c_cmpp_submit (dEndTime );
Loop
Fetch c_cmpp_submit into iId;
Exit when c_cmpp_submit % notfound; iCount: = iCount + 1; insert into cmpp_submit_backup select * from cmpp_submit where id = iId;
Delete from cmpp_submit where id = iId; if (iCount = 1000) then -- submit each 1000 entries
Begin
Commit;
End;
End if;
End loop; -- end of loop
Close c_cmpp_submit; commit; return;
EXCEPTION
WHEN OTHERS THEN
BEGIN
Rollback;
If c_cmpp_submit % isopen then
Close c_cmpp_submit;
End if; EXCEPTION
WHEN OTHERS THEN
NULL;
END;
End CMPP_SUBMIT_REMOVE_PROCEDURE;
This is a database Stored Procedure instance tutorial