当前位置:数据库 > Oracle >>

oracle rownum分页出现重复数据

oracle rownum分页出现重复数据
 
通常一般的分页语句如下:
 
select *
from (
select row_.*, rownum rownum_
from ( select p.id from table1 p
order by p.DATA_UPDATE_TIME desc )
row_ where rownum <= ?) b
where b.rownum_ >?

 

 
当红字部分的 DATA_UPDATE_TIME 不能唯一确定记录的顺序就会出现这个问题,比如有重复的DATA_UPDATE_TIME 。
 
只要将语句写成:
 
select * from (    

select row_.*, rownum rownum_    

from (   

select p.id from table1 p    

order by p.DATA_UPDATE_TIME desc    

) row_   )    

where rownum_ > ? and rownum_ <= ? 

 

 
就ok.
 
另一种改法:
 
select *
from (
select row_.*, rownum rownum_
from ( select p.id from table1 p
order by p.DATA_UPDATE_TIME desc,p.id desc )
row_ where rownum <= ?) b
where b.rownum_ >?

 

 
再加一个不重复的也就行了
 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,