Simple Oracle pagination

Tagged: Database, Oracle Date: 22nd, November 2006

Alot of folks have problems when they first transfer to Oracle from MySQL.
Most of those problems are cosed by absence of LIMIT.

Just to give you all a hint in the right direction here is the simplest “pagination” query used on Oracle.

(select * from emp
where rownum <=var)
minus
(select * from emp
where rownum<=(var-100))

ex.
var = 100 Will give first 100 results and var = 200 will give next 100 results.

One Response to “Simple Oracle pagination”

  1. James Holder:

    I don’t think that is going to work in oracle, especially without an order by clause, and even then I don’t think it will always work. Since there is no guarantee that oracle will return the records in the same order, even in the same query, and rownum is only a pseudo-cloumn at that.You’d have to query and order by, and then requery that ordered query to get a recordset that actually has the rownums correctly assigned.

    To use the minus statement i think you’d have to do something like:
    (select * from
    (select * from emp
    where rownum

Leave a Reply