oracle分頁基本語法

–分頁:
–mysql: limit
–oracle:rownum僞列
–僞列:在表結構中不存在的列
–rowid僞列:用於唯一標識一行記錄
–rownum僞列:行號

select * from emp;–看不到行號
–select *,rownum from emp;–報錯

select e.*,rownum from emp e;–正確的

–rownum:行號是從1開始的,也就是有了1纔會有2
select e.*,rownum from emp e where rownum=2;–獲取不到數據

–分頁
–每頁顯示2條,顯示第2頁的數據
–pageIndex:第幾頁(當前頁碼)
–pageSize:每頁顯示的記錄數
–startRow:(pageIndex-1)*pageSize==>(2-1)2==>2
–endRow:pageIndex*pageSize==>2*2=4
–select * from emp where rownum>startRow and rownum<=endRow
/*
select * from(
select e.*,rownum from emp e where rownum<=endRow
)tmp
where tmp.rownum>startRow
*/
select e.*,rownum from emp e;
select * from (
select e.*,rownum rn from emp e where rownum<=4
) tmp
where tmp.rn>2;

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