小编Ted*_*son的帖子

Oracle 分页查询性能

我是 Oracle 的新手,我注意到分页查询采用这种格式。

select * 
from ( select /*+ FIRST_ROWS(n) */ 
         a.*, ROWNUM rnum 
       from
         ( your_query_goes_here with filter and order by ) a 
       where
         ROWNUM <= :MAX_ROW_TO_FETCH ) 
where
  rnum  >= :MIN_ROW_TO_FETCH;
Run Code Online (Sandbox Code Playgroud)

http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html

为什么有一个额外的外部选择来拆分 min 和 max rownum where 子句?这是否同样具有性能和正确性?

select /*+ FIRST_ROWS(n) */
  *
from 
  ( your_query_goes_here with filter and order by )
where
  ROWNUM between :MIN_ROW_TO_FETCH and :MAX_ROW_TO_FETCH
Run Code Online (Sandbox Code Playgroud)

由于内部查询对值进行过滤和排序,ROWNUM 不应该已经正确了吗?

oracle

5
推荐指数
1
解决办法
6871
查看次数

标签 统计

oracle ×1