[20130803]ORACLE 12C TOP N SQL實現分頁功能.txt
[20130803]ORACLE 12C TOP N SQL實現分頁功能.txt
參考連結:
SQL> @ver
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
select * fro emp;
--檢視執行計劃:
--實際上本質還是使用分析函式ROW_NUMBER()。只不過這樣寫簡單一些。
參考連結:
SQL> @ver
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
select * fro emp;
SQL> SELECT * FROM emp ORDER BY empno ;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
7566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
7782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10
7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
7839 KING PRESIDENT 1981-11-17 00:00:00 5000 10
7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
7900 JAMES CLERK 7698 1981-12-03 00:00:00 950 30
7902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
7934 MILLER CLERK 7782 1982-01-23 00:00:00 1300 10
14 rows selected.
SQL> SELECT * FROM emp ORDER BY empno offset 5 rows FETCH next 5 ROWS ONLY;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
7782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10
7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
7839 KING PRESIDENT 1981-11-17 00:00:00 5000 10
7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30--注意一個細節,這種方式sqlplus沒有14 rows selected.相似的提示資訊。除非next N能全部取完。
--檢視執行計劃:
SQL> @dpc '' ''
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------
SQL_ID dnncqfs9xrpc7, child number 0
-------------------------------------
SELECT * FROM emp ORDER BY empno offset 5 rows FETCH next 5 ROWS ONLY
Plan hash value: 2801941731
----------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)|
----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | 2 (100)|
|* 1 | VIEW | | 14 | 2 (0)|
|* 2 | WINDOW NOSORT STOPKEY | | 14 | 2 (0)|
| 3 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 2 (0)|
| 4 | INDEX FULL SCAN | PK_EMP | 14 | 1 (0)|
----------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(("from$_subquery$_002"."rowlimit_$$_rownumber"<=CASE
WHEN (5>=0) THEN 5 ELSE 0 END +5 AND
"from$_subquery$_002"."rowlimit_$$_rownumber">5))
2 - filter(ROW_NUMBER() OVER ( ORDER BY "EMP"."EMPNO")<=CASE WHEN
(5>=0) THEN 5 ELSE 0 END +5)
--實際上本質還是使用分析函式ROW_NUMBER()。只不過這樣寫簡單一些。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-767753/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20130803]ORACLE 12C RMAN 功能增強.txtOracle
- [SQL Server]分頁功能的實現SQLServer
- aspnetpager+repeater+oracle實現分頁功能Oracle
- 分頁功能的實現
- Oracle常見SQL分頁實現方案介紹OracleSQL
- oracle資料庫用sql實現快速分頁Oracle資料庫SQL
- 使用 jQuery 實現分頁功能jQuery
- web 實現分頁列印功能Web
- SQL Server--實現 Limit m, n 的功能SQLServerMIT
- DjangoRestFramework 實現分頁功能與搜尋功能DjangoRESTFramework
- 文章內容分頁功能實現
- jsp分頁功能的實現JS
- DataGridView分頁功能的實現View
- TOP N 查詢 SQLSQL
- 12C SQL-TOPSQL
- Java Web(十一) 分頁功能的實現JavaWeb
- 如何在SQL Server中實現 Limit m,n 的功能SQLServerMIT
- AWR TOP SQL實現SQL
- WPF DataGrid分頁功能實現程式碼
- 【清清月兒】用SQL 2005的ROW_NUMBER() 實現分頁功能SQL
- 分組求TOP N記錄
- Oracle 12c中增強的PL/SQL功能OracleSQL
- Vue + Element UI + Lumen 實現通用表格功能 - 分頁VueUI
- oracle sql分頁查詢(一)OracleSQL
- Vue + element.ui table 分頁功能+搜尋功能的實現VueUI
- 12C SQL Translation Framework.txtSQLFramework
- 用sql實現的n王后SQL
- ORACLE TOP SQLOracleSQL
- SQL Server 2005快速Web分頁的實現SQLServerWeb
- elementUI實現分頁UI
- 分頁的實現
- struts2.0+E3.Table0.8分頁功能的實現
- ASP.NET中Repeater控制元件實現分頁功能ASP.NET控制元件
- [Oracle Script] Top sqlOracleSQL
- MySql/Oracle和SQL Server的分頁查MySqlOracleServer
- [20170603]12c Top Frequency histogram.txtHistogram
- vue + axios 實現分頁引數傳遞,高階搜尋功能實現VueiOS
- 【專案實戰】---SQL真分頁SQL