oracle 在oracle中只检索表的第二行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5548185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
retrieve only second row of the table in oracle?
提问by Venkat
Can anyone help, how to retrieve exactly 2nd row from the table in oracle?
任何人都可以帮忙,如何从oracle 的表中准确检索第二行?
回答by Justin Cave
Since the rows in a table are inherently unordered, the concept of "first" and "second" requires that you specify some way of enforcing order (i.e. an ORDER BY clause). The simplest way to do this is to use an analytic function
由于表中的行本质上是无序的,“第一”和“第二”的概念要求您指定某种强制顺序的方式(即 ORDER BY 子句)。最简单的方法是使用解析函数
SELECT *
FROM (SELECT a.*,
row_number() OVER (ORDER BY some_column) rn
FROM your_table a)
WHERE rn = 2;
You could also use ROWNUM though that requires an additional level of nesting
您也可以使用 ROWNUM 虽然这需要额外的嵌套级别
SELECT *
FROM (SELECT b.*, rownum rn
FROM (SELECT *
FROM your_table a
ORDER BY some_column) b
WHERE rownum <= 2)
WHERE rn > 1
回答by Venkat
Thanks for your answers,now i found the solution for this,
感谢您的回答,现在我找到了解决方案,
select * from
(select rownum rn,column1,column2,...,columnn from tablename)
where
rn=2
Now you can check this and post your valuable comments.
现在你可以检查这个并发表你的宝贵意见。