order by 容易出现的bug记录

时间:2023-03-10 03:04:05
order by 容易出现的bug记录
  1. 写分页查询时遇到一个问题:

在order by create_time 的时候,假设所有数据的create_time 值相同,那么

使用:select * from ( selelct s.*,rownum rn from t_student s where rownum <= 10 order by s.create_time) a where a.rn >5

和  select * from ( selelct s.*,rownum rn from t_student s where rownum <= 15 order by s.create_time) a where a.rn >10

可能查到相同的数据。

order by 使用时需要注意相同值排序情况,可以添加id排序!

select * from ( selelct s.*,rownum rn from t_student s where rownum <= 15 order by s.create_time,s.id) a where a.rn >10