Oracle"LIMIT n,m"相等的 [英] Oracle "LIMIT n,m" equivalent
问题描述
可能重复:
如何限制数量oracle查询返回的行数?
Possible Duplicate:
How do I limit the number of rows returned by an oracle query?
我有这个查询
select * from pr_device_reading order by date_reading DESC
注意,该查询是规范化的,由方法构造,并且表名将根据方法的参数而变化,因此我无法指定列名(并且我确实希望所有无论如何,结果中的列).
Note that 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).
相当于什么
SELECT *
FROM pr_lecture_combustibles
ORDER BY date_lecture DESC
LIMIT 10,20;
使用Oracle SQL吗?
using Oracle SQL?
我尝试过
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.
谢谢
推荐答案
如果您可以接受为行号添加额外的列,则可以应用ROW_NUMBER
分析函数并执行类似的操作
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
SELECT *
FROM (SELECT a.*,
ROW_NUMBER() OVER( order by date_lecture desc ) rn
FROM pr_lecture_combustibles a)
WHERE rn BETWEEN 10 AND 20
但是您将获得表中的所有列加 RN
列
But you'll get all the columns in the table plus the RN
column
这篇关于Oracle"LIMIT n,m"相等的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!