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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:24:58
Original
1161 people have browsed it

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template