SQL stored procedure instance tutorial

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.