ORACLE數據庫分頁寫法

oracle數據庫的分頁與MySQL數據庫分頁不同,存在一點差異,詳細介紹如下:

-- 不能對ROWNUM使用>(大於1的數值)、>=(大於或等於1的數值)、=(大於或等於1的數值),否則無結果

-- 所以直接用只能從1開始
-- rownum >10 沒有記錄,因爲第一條不滿足去掉的話,第二條的rownum又成了1,所以永遠沒有滿足條件的記錄。
select * from student where rownum>=1;

--如果想要用rownum不從1開始,需按下面方法使用
select a1.* from (select student.*,rownum rn from student) a1 where rn >5;


--分頁查詢一
select * from (select a1.*,rownum rn from (select * from student) a1 where rownum <=5) where rn>=2;

--分頁查詢二
select a1.* from (select student.*,rownum rn from student where rownum <=5) a1 where rn >=3;

--分頁查詢三
select a1.* from (select student.*,rownum rn from student) a1 where rn between 3 and 5;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章