Oracle的rownum原理和使用

我是社区第2725位番薯,欢迎点我头像关注我哦~
Oracle中,要按特定条件查询前N条记录,用个rownum就搞定了。    select * from emp where rownum <= 5
    而且书上也告诫,不能对rownum用">",这也就意味着,如果你想用
    select * from emp where rownum > 5
    则是失败的。要知道为什么会失败,则需要了解rownum背后的机制:
    1 Oracle executes your query.
    2 Oracle fetches the first row and calls it row number 1.
    3 Have we gotten past row number meets the criteria? If no, then Oracle discards the row, If yes, then Oracle return the row.
    4 Oracle fetches the next row and advances the row number (to 2, and then to 3, and then to 4, and so forth)。
    5 Go to step 3.
Oracle的rownum原理和使用 .rar (5.38 KB, 下载次数: 29)

发表于 2012-4-17 20:12:20
呵呵,rownum使用起来挺方便的
发表于 2012-4-18 11:58:06
不错,顶了
发表于 2012-4-19 14:04:24
{:soso_e113:}目前做的一个进销存报表里面取数就用到rownum
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

3回帖数 1关注人数 5830浏览人数
最后回复于:2012-4-19 14:04

返回顶部 返回列表