在oracle中仅检索表的第二行? [英] retrieve only second row of the table in oracle?

查看:157
本文介绍了在oracle中仅检索表的第二行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮忙,如何从oracle中的表中准确检索第二行?

Can anyone help, how to retrieve exactly 2nd row from the table in oracle?

推荐答案

由于表中的行本质上是无序的,因此第一"和第二"的概念要求您指定某种执行顺序的方法(即ORDER) BY子句).最简单的方法是使用解析函数

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

SELECT *
  FROM (SELECT a.*,
               row_number() OVER (ORDER BY some_column) rn
          FROM your_table a)
 WHERE rn = 2;

您还可以使用ROWNUM,尽管这需要附加的嵌套级别

You could also use ROWNUM though that requires an additional level of nesting

SELECT *
  FROM (SELECT b.*, rownum rn
          FROM (SELECT *
                  FROM your_table a
                 ORDER BY some_column) b
         WHERE rownum <= 2)
 WHERE rn > 1

这篇关于在oracle中仅检索表的第二行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆