Monday, October 26, 2009

Oracle Pagination

In case you want to retrieve records from a query paginated, for a given range of start to end row, the following will do the trick.


SELECT *
FROM (SELECT acct_id, session_id, ROW_NUMBER () OVER (ORDER BY acct_id) AS rn
            FROM tb_cwlogin
            ORDER BY acct_id)
WHERE rn BETWEEN 1000 AND 1050

There is no issue with ORDER BY clause as well as with the usual "ROWNUM" method.
 
Hope this helped :)

No comments: