先來定義分頁語句將要用到的幾個參數:
int currentPage ; //當前頁
int pageRecord ; //每頁顯示記錄數
以之前的ADDRESSBOOK數據表為例(每頁顯示10條記錄):
一、SqlServe下載 分頁語句
String sql = "select top "+pageRecord +" * from addressbook where id not in (select top "+(currentPage-)*pageRecord +" id from t_user)"; // (currentPage-)*pageRecord : 是指從第幾個記錄開始
第二頁SQL演示:
select top 20 * from addressbook where id not in (select top 10 id from addressbook)
二、MySQL數據庫分頁語句
String sql = "select * from addressbook where limit "+(currentPage-)*pageRecord +","+pageRecord +""; //select * from 表名 【條件】limit M,N; //M為從第幾個記錄開始,比如每頁顯示條記錄,第二頁就必須從第條記錄開始 //N每頁讀幾個數據
第二頁SQL演示:
select * from addressbook where limit 10,10
三、Oracle數據庫分頁語句
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
以上所述是小編給大家介紹的Oracle、MySQL和SqlServe三種數據庫分頁查詢語句的區別介紹,希望對大家有所幫助!