How to return last used record?
It looks like you are looking for SEQUENCE, simple usage: 

CREATE SEQUENCE ip_seq
 START WITH     1
 INCREMENT BY   1
 NOCACHE
 NOCYCLE;


and then in select:

where id = ip_seq.nextval % ip_table_size