connect user/Password@service_odbc

spool clearProdReport5.log

alter system set UNDO_RETENTION=1;


VARIABLE GapTest NUMBER

begin
loop
	:GapTest := 0;
	select count(link) into :GapTest from TABLEAPURGER where DatePurge < (to_char(sysdate-1460,'YYYY-MM-DD%'));
	IF :GapTest>0 then
		delete TABLEAPURGER where DatePurge < (to_char(sysdate-1460,'YYYY-MM-DD%')) and rownum < 200000;  
		commit;
	else
		exit;
	end if;
end loop; 
end;
/

alter system set UNDO_RETENTION=900;


spool off;
