zhaoxiaol48 2016-02-27 22:15 采纳率: 100%
浏览 1443
已采纳

为什么这条sql分页无效?

SELECT * FROM (SELECT ROWNUM rn, stu.* FROM test_tab_stu stu WHERE ROWNUM > 9) WHERE rn < 21;

DB结构

id number类型
name varchar2类型

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-02-27 22:18
    关注

    [1] rownum不支持以下方式的查询
    a: select * from area where rownum > 2;
    b: select * from area where rownum = n; --where n is a integer number lager than 1
    注:rownum只支持select * from area where rownum =1的查询。Oracle的官方文档说明如下:
    Conditions testing for ROWNUM values greater than a positive integer are always false.
    For example, this query returns no rows:
    SELECT * FROM employees
    WHERE ROWNUM > 1;
    The first row fetched is assigned a ROWNUM of 1 and makes the condition false. The
    second row to be fetched is now the first row and is also assigned a ROWNUM of 1 and
    makes the condition false. All rows subsequently fail to satisfy the condition, so no
    rows are returned.
    因为rownum是根据查询的结果集来对记录进行编号,所以当你查询rownum大于2的记录时会得到一个空的结果集。因为当oracle查询得到第1条记录时,发现rownum为1不满足条件,然后就继续查询第2条记录,但此时第2条记录又被编号为1(也即rownum变为1),所以查询得到的始终是rownum=1,因此无法满足约束,最终查询的结果集为空。

    http://blog.csdn.net/mitedu/article/details/3584399

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码