Oracle的分页还真是挺恶心地,不像mysql直接Limit就搞定
select name from student limit 0,20;
Oracle需要借助rownum实现:
select *
from (
select s.*, rownum as rn from student s where rownum <= 10
) m
where m.rn > 0
如果要增加排序,可以引入order by
select * from (
select c.*, rownum as rn from (
select rownum as row_num, b.* from (
select * from student
--这里可以写复杂的join逻辑
) b
order by b.storecode desc
) c
where rownum <= 10
) m
where m.rn > 0
本文转自博客园xingoo的博客,原文链接:sql基础知识:分页+排序,如需转载请自行联系原博主。
时间: 2024-10-22 02:16:39