当前位置:Gxlcms > mysql > oracleVSmysql的分页查询

oracleVSmysql的分页查询

时间:2021-07-01 10:21:17 帮助过:22人阅读

首先是Oracle: String sql = select * from ( select t.*,rownum as num from (select * from user1 where 1=1 ; SetEntryString, Object set = m.entrySet(); Iterator io = set.iterator(); while (io.hasNext()) { Map.EntryString, Object me = (Map.En

首先是Oracle:

String sql = " select * from ( select t.*,rownum as num from (select * from user1 where 1=1 ";

Set> set = m.entrySet();
Iterator io = set.iterator();
while (io.hasNext()) {
Map.Entry me = (Map.Entry) io.next();
if("username".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " and " + me.getKey() + " like '%"+ me.getValue() +"%'" ;
}
if("startTime".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " and " + me.getKey() + " >= '" + me.getValue() +"'";
}
if("endTime".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " and " + me.getKey() + " <= '" + me.getValue() +"'";
}
if("sort".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " order by " + me.getValue() ;
}
if("order".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " " + me.getValue();
}
}
sql += " )t) " ;
sql = sql +" where num >=" + (currentPage-1)*pageSize +" and num<=" + currentPage*pageSize+"" ;


接着是MySQL:

String sql = " select * from user where 1=1 ";

Set> set = m.entrySet();
Iterator io = set.iterator();
while (io.hasNext()) {
Map.Entry me = (Map.Entry) io.next();
if("username".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " and " + me.getKey() + " like '%"+ me.getValue() +"%'" ;
}
if("startTime".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " and " + me.getKey() + " >= '" + me.getValue() +"'";
}
if("endTime".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " and " + me.getKey() + " <= '" + me.getValue() +"'";
}
if("sort".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " order by " + me.getValue() ;
}
if("order".equals(me.getKey()) && !"".equals(me.getValue())){
sql += " " + me.getValue();
}
}
sql = sql +" limit " + (currentPage-1)*pageSize +" , " + pageSize ;

pageSize 该页有多少条数据,currentPage该页码

人气教程排行