oracle分页查询语句,java得到分页查询语句的方法

oracle分页查询语句
Sql代码
select * from ( select a.*, rownum rn from (select * from table_name) a where rownum <= 40 ) where rn >= 21

java得到分页查询语句的方法
Java代码
/**
* 得到分页查询的语句
* @param queryString
* @param pageIndex
* @param pageSize
* @return
*/
public String getPageQl(String queryString, int pageIndex, int pageSize){
//select * from ( select a.*, rownum rn from (select * from table_name) a where rownum <= 40 ) where rn >= 21
String ql = "select * from ( select page_.*, rownum rn from ("+queryString+") page_ where rownum <= "+pageIndex*pageSize+" ) where rn > "+(pageIndex-1)*pageSize;
//log.info(ql);
return ql;
}

排序的时候,最好再加上按id排序,解决翻页数据重复的问题。

你可能感兴趣的:(JAVA,oracle,java,sql)