【Oracle】从12c开始支持的Oralce新分页方案

前篇:https://www.cnblogs.com/heyang78/p/11830159.html

新方案:

select * from emp order by id offset 100 rows fetch next 10 rows only

业务查询语句:select * from emp order by id 

100:起始位置

10:页容量

传统分页方案:
select * from (select a.*,rownum as rn from (select * from emp order by id) a where rownum<=111 ) b where b.rn>100

业务查询语句:select * from emp order by id 

111:中止位置

100:起始位置

据有限实验,目前的简单sql两种方案效率相当,以后有新发现再行更新。

END

 2021年11月7日增补

将此分页语句写成函数就是:

public abstract class BaseMapperSql {
    protected String getPagedSql(String realSql,int start,int end) {
        StringBuilder sb=new StringBuilder();
        
        sb.append(" select * from ( select a.*,rownum as rn from (");
        sb.append(realSql);
        sb.append(" ) a where rownum<="+end);
        sb.append(" ) b where b.rn>"+start);
        
        return sb.toString();
    }
}

2021年11月7日

原文地址:https://www.cnblogs.com/heyang78/p/15336400.html