Home >Database >Mysql Tutorial >Oracle数据库用SQL实现快速分页

Oracle数据库用SQL实现快速分页

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:24:581157browse

Oracle采用嵌套3层的查询语句结合rownum来实现分页,这在Oracle上是最快的方式,如果只是一层或者两层的查询语句的rownum不能支持

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;

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn