以前在写oracle分页时的sql是:
(1)
select *
from (select a.*, rownum rnum
from (select id, data
from t order by id, rowid) a
)
where rnum >= 148 and rnum<=151;
或者
(2)
select *
from (select a.*, rownum rnum
from (select id, data
from t order by id, rowid) a
where rownum <= 151 )
where rnum >= 148;
最近在开发中同事说第(1)种效率不好,而第(2)种在只有唯一值(列)的时间才能正常排序,以前一直用第(1)种,今天同事找到如下的方式,解决了 第(2)种唯一值(列)排序的问题,如下:
(3)
select *
from (select a.*, rownum rnum
from (select id, data
from t order by id, rowid) a
where rownum <= 151 )
where rnum >= 148;
PS:主要是添加了rowid这个字段。
参考网站:http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html
时间: 2024-11-07 20:36:58