Home > Database > Mysql Tutorial > body text

Oracle数据库中rownum分页

WBOY
Release: 2016-06-07 17:11:01
Original
1541 people have browsed it

测试人员在项目测试中发现查询结果列表分页的时候,有的数据在好几页中重复显示,有的则一次都不显示,经过分析sql,原来问题出在

测试人员在项目测试中发现查询结果列表分页的时候,有的数据在好几页中重复显示,有的则一次都不显示,经过分析sql,原来问题出在rownum分页上了。在Oracle中使用rownum分页,以前是按以下方式写:

select * from
(select a.*,rownum rn from table a where 条件 ) b
where b.rn between 1 and 20 ;

在单表查询时,这个结果分页显示不会出问题,但当多表关联时,rownum就会乱,现在改为如下方式,,按指定字段排序后再获取rownum,这样每次查询出来的结果就一致了:

select * from
(select a.*,rownum rn from
(select * from table c,table1 d where 条件 order by c.id desc) a
) b where b.rn between 1 and 20

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template