我正在使用以下过程将数据从一个表归档到另一个表。
create or replace PROCEDURE CHECK_TWO AS
v_insert_count number;
v_delete_count number;
v_initial_count number;
BEGIN
SELECT count(*) into v_initial_count from process_state where tstamp BETWEEN ADD_MONTHS(trunc(SYSDATE,'MONTH'), -12) AND LAST_DAY(TRUNC(SYSDATE, 'MONTH') - 4);
dbms_output.put_line(v_initial_count);
insert into process_state_archive select * from process_state where tstamp BETWEEN ADD_MONTHS(trunc(SYSDATE,'MONTH'), -12) AND LAST_DAY(TRUNC(SYSDATE, 'MONTH') - 4);
v_insert_count := sql%rowcount;
dbms_output.put_line(v_insert_count);
delete process_state where tstamp BETWEEN ADD_MONTHS(trunc(SYSDATE,'MONTH'), -12) AND LAST_DAY(TRUNC(SYSDATE, 'MONTH') - 4);
v_delete_count := sql%rowcount;
dbms_output.put_line(v_delete_count);
if v_insert_count = v_delete_count AND v_initial_count= v_insert_count then
commit;
else
rollback;
end if;
END CHECK_TWO;
在这个过程中,我想处理服务器不可用或数据库关闭等异常或任何其他与环境相关的问题。如何在我的存储过程中处理这些场景。谁能告诉我??