导读 | 常用关系数据库分页SQL都是不相同的,不过大同小异。 |
下面是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 <= 3;
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 <= 3 ) 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分页才加入了多个子查询。
原文来自:
本文地址://lrxjmw.cn/oracle-data-paging.html编辑:薛鹏旭,审核员:逄增宝
Linux大全:
Linux系统大全: