使用oracle数据库查询数据时,每页展示数据有限,大部分情况下需要分页展示。如每页显示10条,一页一页查询出来。下面就来介绍下oracle分页实现
1、普通查询
select * from table_Name t order by active_count desc;
2、查询第一条记录
select * from (select * from table_Name order by active_count desc) where rownum = 1;
查询前3条:类似Sqlserver中的TOP 3
select * from (select * from table_Name order by active_count desc) where rownum
4、查询第2至第3条记录
select * from (select t.*, rownum as no from (select * from table_Name order by active_count desc) t) where no between 2 and 3
5、在TOP3条记录的基础上查询第2至第3条记录
select * from (select t.*, rownum as no from (select * from table_Name order by active_count desc) t where rownum where no between 2 and 3
6、查询第2条以后的记录
select * from (select t.*, rownum as no from (select * from table_Name order by active_count desc) t) where no >=2
解释:
rownum 是在已产生数据的基础上伪生成的编号,所以 使用rownum 必须在已有数据的基础上,因此Oracle分页才加入了多个子查询。
本文来源:www.lxlinux.net/9153.html,若引用不当,请联系修改。