oracle实现分页与mysql实现分页功能

时间:2022-09-20 20:36:58

1.oracle所用的sql语句

String sql = "select * from ( select t.*, ROWNUM RN from ( 
select * from tblmetadatainfo where 1=1 ";
if ((!"".equals(fileName)) && fileName != null) {
sql += " and backupRealName like '%" + fileName.trim() + "%'";
}
if ((!"".equals(fromTime)) && fromTime != null) {
sql += " and backupDate >= to_date('" + fromTime + " 00:00:00','yyyy-mm-dd hh24:mi:ss')";
}
if ((!"".equals(endTime)) && endTime != null) {
sql += " and backupDate<= to_date('" + endTime + " 23:59:59','yyyy-mm-dd hh24:mi:ss')";
}
sql += "order by id desc ) t WHERE ROWNUM <= " + pagenum * 15
+ ") WHERE RN >=" + (pagenum - 1) * 15 + " ";

pageNum是前台传递来的页码,每页有15个记录

2.mysql所用的sql语句

sql="select * from usertablel where userid limit " +((pageNow-1)*pageSize)+","+pageSize;