从工资中选择 rownum,其中 rownum=3;
如何使用“rownum”关键字从任何表中检索第三行(我使用的是oracle-10g)
How to retrieve third row from any table using "rownum" key word ( i am using oracle-10g)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当查询生成行时,Oracle 按顺序将值分配给 ROWNUM - 因此,获取的第一行获取 ROWNUM=1,获取的第二行获取 ROWNUM=2,获取的第三行获取 ROWNUM=3,等等。 注意 - 对于一行要分配 ROWNUM=3,必须获取前面的两行。这就是您的查询不返回任何行的原因。您向数据库询问已获取的第三行 - 但从未获取过第 1 行和第 2 行。
要进行演示,请尝试运行以下查询:
要解决您的问题,请尝试以下操作:
分享并享受。
Oracle assigns values to ROWNUM sequentially as rows are produced by the query - thus, the first row fetched gets ROWNUM=1, the second row fetched gets ROWNUM=2, the third row fetched gets ROWNUM=3, etc. Notice - for a row to be assigned ROWNUM=3 two preceding rows MUST be fetched. And this is why your query returns no rows. You're asking the database for the third row fetched - but rows 1 and 2 have never been fetched.
To demonstrate, try running the following queries:
To work around your problem, try the following:
Share and enjoy.
您需要执行类似的操作
rownum
直到谓词阶段之后才被分配,因此rownum = 3
将始终为 false。使用 CTE 或派生表,然后您可以从其外部访问rownum
。You would need to do something like this
rownum
is not assigned until after the predicate phase sorownum = 3
will always be false. Use a CTE or derived table then you can access therownum
from outside it.这是不正确的。这将始终返回“3”,因为您选择的是 ROW_NUMBER。
它应该是“select *”,如下所述:
This is incorrect. This will always return '3', because you are selecting ROW_NUMBER.
It should instead be "select *", as mentioned below:
rownum 是薪资表中的实际列吗?如果不是,根据您的数据库类型,rownum 可能不受支持。
Is rownum an actual column in your salary table? If not, depending on your DB type, rownum is likely not supported.