欢迎投稿

今日深度:

oracle rownum分页出现重复数据

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_ >?

 

 
再加一个不重复的也就行了
 

www.htsjk.Com true http://www.htsjk.com/oracle/21466.html NewsArticle oracle rownum分页出现重复数据 oracle rownum分页出现重复数据 通常一般的分页语句如下: select *from (select row_.*, rownum rownum_from ( select p.id from table1 porder by p.DATA_UPDATE_TIME desc )row_ where rownum...
相关文章
    暂无相关文章
评论暂时关闭