ORCALE数据库实现分页查询可以使用row_number()函数或者使用rownum 虚列两种方法。
JAVA中的代码:
String usedsql = sql.trim();
boolean isForUpdate = false;
if (usedsql.toLowerCase().endsWith(" for update")) {
usedsql = usedsql.substring(0, usedsql.length() - MIN_VALUE);
isForUpdate = true;
}
String usedsql = sql.trim();
boolean isForUpdate = false;
if (usedsql.toLowerCase().endsWith(" for update")) {
usedsql = usedsql.substring(0, usedsql.length() - MIN_VALUE);
isForUpdate = true;
}
StringBuffer pagingSelect = new StringBuffer(usedsql.length() + MAX_VALUE);
if (offset > 0) {
pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
} else {
pagingSelect.append("select * from ( ");
}
pagingSelect.append(usedsql);
if (offset > 0) {
pagingSelect.append(" ) row_ ) where rownum_ between " + offset + " and " + limit);
} else {
pagingSelect.append(" ) where rownum <= " + limit);
}
if (isForUpdate) {
pagingSelect.append(" for update");
}
if (isForUpdate) {
pagingSelect.append(" for update");
}