一、Oracle 分页查询
/**
* 将查询sql转换为分页sql
* @param sql {查询sql}
* @param offset {开始行数}
* @param limit {截至行数}
* @return {查询中不可以有相同的字段名}
*/
public static String limitSql(String sql,Integer offset,Integer limit) {
if (isEmpty(sql)) return sql;
String limitSql = "SELECT * FROM ( SELECT row_.*, ROWNUM rownum_ FROM ( " +
sql +
" ) row_ ) WHERE rownum_ > " + (offset!=null?offset:0) +
" AND rownum_ <= " + (limit!=null?limit:10);
return limitSql;
}
@Test
public void test_029(){
String sql = "SELECT * FROM tableName";
System.out.println(CPUtil.limitSql(sql, 0, 10));//调用公用静态方法分页
}