共计 885 个字符,预计需要花费 3 分钟才能阅读完成。
★先来定义分页语句将要用到的几个参数:
int currentPage ; // 当前页
int pageRecord ; // 每页显示记录数
以之前的 ADDRESSBOOK 数据表为例(每页显示 10 条记录):
一、SqlServe 下载 分页语句
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 数据库分页语句
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 数据库分页语句
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
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-05/131215.htm