Home >Database >Mysql Tutorial >Oracle 分页的三种情况

Oracle 分页的三种情况

WBOY
WBOYOriginal
2016-06-07 17:23:41914browse

Oralce 的分页一共有三种 1. rownum select * from emp 2. 显示rownum[Oracle 分配的] select a1.* ,rownum rn from (select *

Oralce 的分页一共有三种

1. rownum

select *  from emp

2. 显示rownum[Oracle 分配的]

select a1.* ,rownum rn from (select * from emp) a1;

3.几个查询的变化

a.指定查询列只需修改最里层的子查询就可以了

b.排序也是只需要修改最里面的就可以了

----------------------------------------------------------

1.按ROWID来分

select * from t-xiaoxi where rowid in (select rid from

(select rownum rn,rid from (select rowid, rid,cid from

t_xiaoxi order by cid desc) where rownum

rn>9980) order by cid desc;

执行时间为0.03秒

2.按分析函数来分

select * from (select t.* ,row_number() over(order by cid

desc ) rk from t_xiaoxi t ) where rk9980;

执行时间为1.01 秒

3.按ROWNUM 来分

select * from (select t.* ,rownum rn from (select * from

t_xiaoxi order by cid desc ) t where rownum

rn>9980 ;

执行时间为0.1秒

其中—t_xiaoxi 为表名,cid为表的关键字段,取按CId降序排序

后的第9981-9999条记录,,t_xiaoxi 表中有70000多条记录

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn