I use a little trick to page and find the total number of rows at the same time. This query gives me the first and last rows, as well as the page that was requested. Using ROW_NUMBER, you can cut the query to 2 selects.
select a, b, r from (
select a, b, rownum r from (
select a, b from test
order by a asc
) order by r desc
) where rownum=1 or r=1 or r between 20 and 30
order by r asc |