Oracle、MySQL和SqlServe分頁查詢的語句區別,oraclesqlserve
★先來定義分頁語句將要用到的幾個參數:
- int currentPage ; //當前頁
- int pageRecord ; //每頁顯示記錄數
以之前的ADDRESSBOOK數據表為例(每頁顯示10條記錄):
一、SqlServe下載 分頁語句
Java代碼
- String sql = "select top "+pageRecord +" * from addressbook where id not in (select top "+(currentPage-1)*pageRecord +" id from t_user)";
- // (currentPage-1)*pageRecord : 是指從第幾個記錄開始
第二頁SQL演示:
select top 20 * from addressbook where id not in (select top 10 id from addressbook)
二、MySQL數據庫分頁語句
Java代碼
- String sql = "select * from addressbook where limit "+(currentPage-1)*pageRecord +","+pageRecord +"";
-
- //select * from 表名 【條件】limit M,N;
- //M為從第幾個記錄開始,比如每頁顯示3條記錄,第二頁就必須從第4條記錄開始
- //N每頁讀幾個數據
第二頁SQL演示:
select * from addressbook where limit 10,10
三、Oracle數據庫分頁語句
Java代碼
- String sqls = "select * from ( select rownum rn,t.* from addressbook t where rownum <= "+currentPage*pageRecord+" ) where rownum > "+(currentPage -1)*pageRecord;
-
第二頁SQL演示:
select * from ( select rownum rn,t.* from addressbook where rownum<= 20 ) where rownum > 10