您的位置:首页 > 数据库 > Oracle

一个奇葩的oracle分页问题,已经知道解决办法,但是不晓得产生问题的原音~

2013-08-27 16:57 501 查看
先看看效果图:如图所示出现两条“诺基亚售后服务”



看看数据库中:根据排序sort查询到的只有一条!!!



下面是调试得到的sql语句:

select * from (select m.*,ROWNUM rn from
(select h.id,h.hotlinesort,h.hotlinename,h.typeid,h.brandid from t_d_hotline h where h.s_isdeleted = 0
order by h.hotlinesort asc) m where ROWNUM <=5) where rn>0;

select * from (select m.*,ROWNUM rn from
(select h.id,h.hotlinesort,h.hotlinename,h.typeid,h.brandid from t_d_hotline h where h.s_isdeleted = 0
order by h.hotlinesort asc) m where ROWNUM <=10) where rn>5;


查询的结果是:

图1是第一页/每页五条:


【图1】

图2是第二页/每页五条:


【图2】

经过对比发现有两条“诺基亚售后服务”~~~~~~~~~~~~~~~~~~~~~~~

(下面是模拟上面的功能)

create table ceshi(id number,name varchar(20),sort number);
truncate table ceshi;
select * from ceshi;
insert into ceshi values(1,'aa',1);
insert into ceshi values(2,'bb',1);
insert into ceshi values(3,'cc',1);
insert into ceshi values(4,'aa',1);
insert into ceshi values(5,'bb',1);
insert into ceshi values(6,'cc',1);
insert into ceshi values(7,'aa',2);
insert into ceshi values(8,'bb',4);
insert into ceshi values(9,'cc',5);
insert into ceshi values(10,'bb',6);
insert into ceshi values(11,'cc',7);

select * from (select m.*,ROWNUM rn from
(select * from ceshi h order by h.sort asc) m where ROWNUM <=5) where rn>0;

select * from (select m.*,ROWNUM rn from
(select * from ceshi h order by h.sort asc) m where ROWNUM <=10) where rn>5;

---------------------------------------------------运行的结果----------------------------------------------------------------------------------

ID NAME
SORT RN

1    aa        1         1

2         bb        1          2

3 cc         1         3

4 aa        1         4

5 bb         1        5

ID NAME
SORT RN

6 cc                 1              6

7 aa                2              7

8 bb                4               8

9 cc                5              9

10 bb               6              10 

没有重复id=5的,为什么?因为结果模拟跟遇到的错误不一致,所以很纠结

想搞弄清楚怎么回事,so,先上博客,后面再去研究~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐