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
Oracle "LIMIT n,m" equivalent
提问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_NUMBER
analytic 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 RN
column
但你会得到表中的所有列加在RN
列