Click here to Skip to main content
15,896,915 members
Articles / Database Development
Tip/Trick

Post on how to do Paging in Oracle

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
2 Feb 2011CPOL 12.6K   1   1
Oracle Paging
It is always difficult to handle paging in Oracle as we need to put an inner query with rownum, and we give a where condition in the outer query with that pseudo rownum column.

This is the conventional way of doing it:
SQL
select * from (select rownum,fld1,fld2,fld3... from bigtable where <<CONDITION>> ) where rownum between 1 to 100

and we say rownum between 101 to 200, and so on...

We can rewrite this in the following way, but we need a running number column in our table. Let's say our running number column name is SYSID. Then, we can write this like:
SQL
Select * from bigtable where <<CONDITION>> and SYSID>=1 and rownum between 1 to 100


The next time we take the greatest sysid from the above return query and execute next step like:
SQL
Select * from bigtable where <<CONDITION>> and SYSID>PREVIOUS GREATEST SYSID and rownum between 1 to 100


When we get a rowcount less than 100, that means we are finished with fetching all the rows.

Limitations

Order By, Group By clauses will not work with this.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Arab Emirates United Arab Emirates
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 1 xyz Pin
Anoop Ananthan27-Dec-11 19:10
professionalAnoop Ananthan27-Dec-11 19:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.