Is there a way to make an Oracle
query behave like it contains a MySQL limit
clause?
(有没有一种方法可以使Oracle
查询像包含MySQL limit
子句那样工作?)
In MySQL
, I can do this:
(在MySQL
,我可以这样做:)
select *
from sometable
order by name
limit 20,10
to get the 21st to the 30th rows (skip the first 20, give the next 10).
(以获得第21至第30行(跳过前20行,给出下10行)。)
The rows are selected after the order by
, so it really starts on the 20th name alphabetically. (这些行是按order by
选择order by
,因此实际上按字母顺序从第20个名称开始。)
In Oracle
, the only thing people mention is the rownum
pseudo-column, but it is evaluated before order by
, which means this:
(在Oracle
,人们唯一提到的是rownum
伪列,但它在 order by
之前 order by
进行评估,这意味着:)
select *
from sometable
where rownum <= 10
order by name
will return a random set of ten rows ordered by name, which is not usually what I want.
(将返回一个随机的十行,按名称排序,这通常不是我想要的。)
It also doesn't allow for specifying an offset. (它也不允许指定偏移量。)
ask by Mathieu Longtin translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…