實現(xiàn)分頁,可以使用嵌套查詢,也可以使用存儲過程。不過存儲過程太復(fù)雜,執(zhí)行效率也不一定高, 所以考試大就用這樣的嵌套語句來實現(xiàn):
SELECT 頁大小 * FROM TestTable
WHERE (ID >(SELECT MAX(id) FROM (SELECT 頁大小*頁數(shù) id FROM TestTable ORDER BY id) AS T)) ORDER BY ID
select * from (select * from scott.emp order by scott.emp.empno) where rownum<=20;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
minus
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
union all
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b where rownum<=10 ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
intersect
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select aa.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=20 ) aa
minus
select bb.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=10 ) bb
select a.empno from (select scott.emp.empno from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from (select scott.emp.empno from scott.emp where rownum<=10 order by scott.emp.empno) b;
SELECT 頁大小 * FROM TestTable
WHERE (ID >(SELECT MAX(id) FROM (SELECT 頁大小*頁數(shù) id FROM TestTable ORDER BY id) AS T)) ORDER BY ID
select * from (select * from scott.emp order by scott.emp.empno) where rownum<=20;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
minus
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno ) a
union all
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from scott.emp b where rownum<=10 ;
select a.empno from (select * from scott.emp where rownum<=20 order by scott.emp.empno) a
intersect
select b.empno from (select * from scott.emp where rownum<=10 order by scott.emp.empno) b ;
select aa.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=20 ) aa
minus
select bb.empno from ( select * from (select * from scott.emp order by scott.emp.empno) a where rownum<=10 ) bb
select a.empno from (select scott.emp.empno from scott.emp where rownum<=20 order by scott.emp.empno) a
minus
select b.empno from (select scott.emp.empno from scott.emp where rownum<=10 order by scott.emp.empno) b;