oracle数据库的分页查询语句

隐身守侯 提交于 2019-12-23 22:50:17

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

对于rownum来说它是oracle系统顺序分配为从查询返回的行的编号,返回的第一行分配的是1,第二行是2,依此类推,这个伪字段可以用于限制查询返回的总行数

1单表查询

start页面的起始位置,size 为页面要展示的信息个数:

SQL语句如下:如果有order by语句,那至少要使用两个子查询

select t.* from (
select tt.id,tt.name,rownum as rwn from (
select id ,name from student order by id
) tt where rownum<10) t where t.rwn>4
2多表查询
多表联合查询可以使用这个语句 ,使用orcle中rownum来控制返回的记录数在多少行到多少行之间。
select * from ( 
select p.*,rownum rwn from product p  inner join productupid pu  on p.id=pu.productid  where rownum<5 
)  where rwn> 2

选择需要的字段,减少网络传输量:
select  res.id from ( 
select p.*,rownum rwn from product p  inner join productupid pu  on p.id=pu.productid  where rownum<5 
) res where rwn> 2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!