sql 存储过程实例教程
create or replace PROCEDURE CMPP_SUBMIT_REMOVE_PROCEDURE
Is
dEndTime date; -- 每次处理是时间点
Is
dEndTime date; -- 每次处理是时间点
-- 取得要处理的数据ID
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 ;
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; -- 计数器
begin
iCount number; -- 计数器
begin
--dEndTime := trunc((SYSDATE - 1/288),'mi'); -- 取得处理时间点,处理5分钟前的数据
dEndTime := trunc(SYSDATE,'mi'); -- 取得处理时间点
dEndTime := trunc(SYSDATE,'mi'); -- 取得处理时间点
iCount := 0; -- 初始化计数
open c_cmpp_submit(dEndTime);
loop
fetch c_cmpp_submit into iId;
exit when c_cmpp_submit%notfound;
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;
delete from cmpp_submit where id=iId;
if ( iCount=1000 ) then -- 每1000条提交一次
begin
commit;
end;
end if;
end loop; -- end of loop
close c_cmpp_submit;
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
BEGIN
rollback;
if c_cmpp_submit%isopen then
close c_cmpp_submit;
end if;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
WHEN OTHERS THEN
NULL;
END;
end CMPP_SUBMIT_REMOVE_PROCEDURE;
这是一款数据库的存储过程实例教程
补充:数据库,mysql教程