ORACLE数据库分页的集中方法

来源:互联网 发布:安心360定位软件 编辑:程序博客网 时间:2024/05/23 13:21

Oracle数据库分页的三种方法

在 做项目中用到了分页,下面说一下oracle分页的方法;

采用伪列 rownum

    查询前10条记录

    [sql]

    select * from t_user t where ROWNUM <10;

    按照学生ID排名,抓取前三条记录

-- 不能对ROWNUM使用>(大于1的数值)、>=(大于或等于1的数值)、=(大于或等于1的数值),否则无结果
-- 所以直接用只能从1开始
-- rownum >10 没有记录,因为第一条不满足去掉的话,第二条的rownum又成了1,所以永远没有满足条件的记录。
select * from student where rownum>=1;

--如果想要用rownum不从1开始,需按下面方法使用
select a1.* from (select student.*,rownum rn from student) a1 where rn >5;


--分页查询一
select * from (select a1.*,rownum rn from (select * from student) a1 where rownum <=5) where rn>=2;

--分页查询二
select a1.* from (select student.*,rownum rn from student where rownum <=5) a1 where rn >=3;

--分页查询三
select a1.* from (select student.*,rownum rn from student) a1 where rn between 3 and 5;

原创粉丝点击