Pagination in Oracle
2014-09-13 18:59
211 查看
Pagination in Oracle
Always we need to present dataset from Database in application. But the dataset is usually too huge to query all the records. So pagination is needed toimprove performance.
Firstly, ROWNUM is involved to implement pagination. ROWNUM is a pseudo-column that returns a column’s position in Oracle database. ROWNUM is evaluated
after records are selected from database and before the execution of ORDER BY clause.
The following filter will return no data
WHERE
ROWNUM > x (x<>0)
WHERE ROWNUM BETWEEN x AND y
However this will work
WHERE ROWNUM < x
A funny magic shown below ROWNUM will out of numeric order
SQL1:
SELECT
A.ROWNUM, A.rowid FROM A
ORDER BY A.rowid, A.ROWNUM
Secondly, an example for pagination provides the SQL to get the dataset of the specified page.
SQL2:
DECLARE
pageNo int, pageSize int;
SELECT A.rowid, A.ROWNUM FROM
(SELECT ROWNUM AS rm, rowid FROM B
WHERE ROWNUM <= pageNo*pageSize) A
WHERE a.rm > (pageNo-1)*pageSize;
Also the SQL3 below also works
SQL3:
SELECT A.rowid, A.ROWNUM FROM
(SELECT ROWNUM AS rm, rowid FROM B) A
WHERE A.rm > (pageNo-1)*pageSize AND A.rm <= pageNo*pageSize;
At the performance point, better to use SQL2
相关文章推荐
- use ROW_NUMBER() for pagination in Oracle and SQLServer
- 040908 Q SQL statement In SqlServer & Oracle --SELECT TOP 0 * FROM & ROWNUM = 0
- 2Gb or Not 2Gb - File limits in Oracle (Part II)
- Methods for Using Java in ORACLE(转荐)
- Send email in oracle
- Temp Table in Oracle
- oracle9问题解决:oracle initialization or shutdown in progress
- MS bug "The connection pool" in Oracle 10g and the data sort according to specified filed on DataGrid control.
- connect to Oracle in Ruby on Rails.
- Sending e-mail from Oracle Server in 10g
- 2Gb or Not 2Gb - File limits in Oracle (Part I)
- How To Use a DataReader Against an Oracle Stored Procedure in Visual C# .NET
- EXPLANIN PLAN 的输出显示ORACLE如何执行SQL语句
- Oracle的in和not in (转)
- ORA-00162 in OracleConnection.Connect
- 2Gb or Not 2Gb - File limits in Oracle (Part II)
- ROWNUM used in ORACLE
- Understanding Pagination in ASP.NET 1.x Mobile Applications
- oracle9问题解决:oracle initialization or shutdown in progress
- Analytic Functions in Oracle 8i and 9i