概述
[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;
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 207499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 307521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 307566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 207654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 307698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 307782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 107788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 207839 KING PRESIDENT 1981-11-17 00:00:00 5000 107844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 307876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 207900 JAMES CLERK 7698 1981-12-03 00:00:00 950 307902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 207934 MILLER CLERK 7782 1982-01-23 00:00:00 1300 1014 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 307782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 107788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 207839 KING PRESIDENT 1981-11-17 00:00:00 5000 107844 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 ONLYPlan 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"<=CASEWHEN (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()。只不过这样写简单一些。
最后
以上就是炙热春天为你收集整理的oracle12c新特性分页,[20130803]ORACLE 12C TOP N SQL实现分页功能.txt的全部内容,希望文章能够帮你解决oracle12c新特性分页,[20130803]ORACLE 12C TOP N SQL实现分页功能.txt所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复