对于一些网站搜索或者BBS经常会要求分页显示,为了快速显示出第一页的信息,需要加first_rows(n)来快速显示最前面的几行数据。实例:
select/*+first_rows(10)*/ *
from (select/*+first_rows(10)*/ t.*,rownum rn
from(select/*+first_rows(10)*/ * from t order by x)
whererownum<=20)
where rn<=10
这就是典型的分页例子,不过排序使用的X列必须有索引,否则的话CBO会忽略FIRST_ROWS(n)而使用ALL_ROWS。