天天看點

完成oracle資料分頁功能

oracel資料庫對查詢語句的要求似乎要嚴格一些,要先“小于”,再“大于”

例:建立表 table students

字段 stuid,sname,age,sex

create table students (
stuid number,
sname varchar2(20),
age number,
sex varchar2(20));      

基本查詢語句

  select * from students

查詢第6到10行的資訊

select * from ( select s.*,rownum rn from students s where rownum <= 10) where rn > 5      

看懂這條sql語句,分頁的核心也就基本上掌握了

private int pageNum = 1;//頁碼
private int nums = 15;//每一頁的行數      

每頁顯示nums行,查詢第pageNum頁:

select * from ( select s.*,rownum rn from students s where rownum <= nums * pageNum) where rn > (pageNum-1) * nums;      

這樣,分頁資訊就查詢出來了

轉載于:https://www.cnblogs.com/goldeneast/p/3406622.html