oracle采用嵌套3层的查询语句结合rownum来实现分页,这在oracle上是最快的方式,如果只是一层或者两层的查询语句的rownum不能支持order by。
程序代码:
复制代码 代码示例:
public String getLimitString(String sql) {
StringBuffer pagingSelect = new StringBuffer(100);
pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
pagingSelect.append(sql);
pagingSelect.append(" ) row_ where rownum ?");
return pagingSelect.toString();
}
sql语句:
select * from ( select row_.*, rownum rownum_ from (select * from scott.emp ) row_ where rownum 2;