Friday, April 20, 2012

Pagination query in oracle

MySQL provides an easy way for paginating the result set.Yeah!!!!! i am talking about LIMIT clause in MySQL.People familiar with MySQL surely enjoy this.Unfortunately oracle doesn't provide any one word solution like MySQL does, but still it is easy enough to achieve that same goal in oracle.Here is a nice and easy solution using inline query :



 
SQL> SELECT * FROM (
       SELECT  x.*, rownum as r FROM (
         SELECT field1,field2,rownum 
         FROM table_name
         ORDER BY field_name
       ) x
     )
     WHERE r BETWEEN start AND end;
NB : Try to avoid * in the innermost SELECT clause if you don't need to pull all the column.This will help
you to increase the query performance.
 
Enjoy happy coding :). 

No comments:

Post a Comment

SyntaxHighlighter