QUOTE:
原帖由
Laurence.li 于 2008-9-24 12:15 发表

其实楼主是希望提高查询的效率,我提供一种方案供参考:
如果每次查询都是desc排序,就干脆建立desc索引:
create index idx1 on test(col1 desc);
analyze table test estimate statistics for table for all indexes for all indexed columns;
select /*+ index(test idx1) */ col1 from test where rownum < 16;
这样查询出来就是降序排列的前15条了。
如果有时查降序,有时又查升序,那还是建立普通索引:
create index idx2 on test(col1);
analyze ......
查asc前15条:
select /*+ index(test idx2) */ col1 from test where rownum < 16;
查desc前15条:
select /*+ index_desc(test idx2) */ col1 from test where rownum < 16;
以上方法供参考,楼主还须多测试,把数据打乱测试一下,确保正确性后,检验效率,目的其实就是希望不再访问表,而仅仅通过索引取出前15条,当然,你这个col1字段应该是not null的,否则你最好在查询里加上where col1 is not null的查询条件
还有就是,sql的执行和oracle的版本也是有关系的,以上方法曾在9i里用过,问题应该不大,更早的版本就不得而知了,呵呵