30 January 2012

Paging in Oracle

To do paging in oracle, the best way is to use:


SELECT * FROM
(
    SELECT a.*, rownum r__
    FROM
    (
        SELECT * FROM ORDERS WHERE CustomerID LIKE 'A%'
        ORDER BY OrderDate DESC, ShippingDate DESC
    ) a
    WHERE rownum < ((pageNumber * pageSize) + 1 )
)
WHERE r__ >= (((pageNumber-1) * pageSize) + 1)


Source: http://stackoverflow.com/questions/241622/paging-with-oracle#241643
Post a Comment