ITPub博客

首页 > 数据库 > Oracle > oracle分页查询小体会

oracle分页查询小体会

Oracle 作者:541106 时间:2013-01-30 17:16:29 0 删除 编辑

今天尝试oracle分页时,遇到一个很常见的问题,就是sql语句不报错,但是没有查询结果

如下:

select a.* from (select c.*,rownum from (select * from mg02) c where rownum<=12) a where rownum>2;

采用另一方式访问:

select a.* from (select c.*,rownum from mg02 c where rownum<=12) a where rownum>2;

仍然无结果,网上搜索一下,才发现原来是少了列别名,rownum是数据库关键词,上面语句中的rownum需要加列别名才能被认为是同一个rownum;正确如下:

select a.* from (select c.*,rownum rn from (select * from mg02) c where rownum<=12) a where rn>2;

select a.* from (select c.*,rownum as rn from mg02 c where rownum<=12) a where rn>2;

建议采用第二个sql语句,减少一次对数据库数据的访问,分页条数较大时,访问效率更高

<!-- 正文结束 -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22881583/viewspace-1117094/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2009-11-15