Pagination in Oracle 12c

oracle-12cstored-procedures

I have 20000 records in a table. I want to fetch 200 records at a time and do either update or delete operation. The next time I fetch 200 records, these previously processed/non-deleted records shouldn't come into picture.I though of using pagination, but could get to the logic of implementing it.Is there any way to achieve it?

Best Answer

You can create a column for update and/or delete status for the records. Do update instead of delete and assign a value that specifies this process. Assign another value for update process so that you can track the record's status.

When fetching you should have a where condition that returns records which have neither of these assigned values. After fetching these 200 records, you can do your delete or update process. I wouldn't use paging for this requirement, but if you want, just add your condition to the below paging

Sample paging:

SELECT * FROM (
    SELECT COL1,COL2,COL3,ROWNUM RNUM
    FROM SAMPLE_TABLE
    WHERE UPD_OR_DELETE NOT IN (1,2) AND ROWNUM < ( (p_page_number * p_page_size) + 1)) a
WHERE rnum >= ( ( (p_page_number - 1) * p_page_size) + 1);