Oracle "LIMIT n,m" 等效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5735600/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:26:18  来源:igfitidea点击:

Oracle "LIMIT n,m" equivalent

mysqlsqloracle

提问by Yanick Rochon

Possible Duplicate:
How do I limit the number of rows returned by an oracle query?

可能的重复:
如何限制 oracle 查询返回的行数?

I have this query

我有这个查询

select * from pr_device_reading order by date_reading DESC

Notethat this query is normalized, constructed by a method, and the table name will change according to the method's argument, so I can't specify the column names (and I do want all the columns in the result anyway).

请注意,此查询已规范化,由方法构造,并且表名将根据方法的参数更改,因此我无法指定列名(无论如何我确实希望结果中的所有列)。

What is the equivalent of

相当于什么

SELECT * 
 FROM pr_lecture_combustibles 
ORDER BY date_lecture DESC 
LIMIT 10,20;

using Oracle SQL?

使用 Oracle SQL?

I have tried

我试过了

SELECT * 
  FROM (SELECT * 
          FROM pr_lecture_combustibles 
         ORDER BY date_lecture DESC) 
 WHERE ROWNUM BETWEEN 10 AND 20;

and other syntax, but I get no result, "missing expression" messages and other errors.

其他语法,但我没有得到任何结果,“缺少表达式”消息和其他错误。

Thanks

谢谢

采纳答案by Justin Cave

If you can accept getting an additional column for the row number, you can apply the ROW_NUMBERanalytic function and do something like this

如果您可以接受为行号增加一列,则可以应用ROW_NUMBER分析函数并执行以下操作

SELECT *
  FROM (SELECT a.*,
               ROW_NUMBER() OVER( order by date_lecture desc ) rn
          FROM pr_lecture_combustibles a)
 WHERE rn BETWEEN 10 AND 20

But you'll get all the columns in the table plusthe RNcolumn

但你会得到表中的所有列RN