常用关系数据库分页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分页才加入了多个子查询。
本文地址:https://www.linuxprobe.com/oracle-data-paging.html
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.