我想我可能只是缺少一些明显的语法,但是选择前 10 条记录,然后是下 10 条记录的 sql (oracle) 是什么?
我尝试使用 rownum,但似乎可以让 rownum > X 和 rownum < Y 起作用。
我会
最佳答案
只有一种相当复杂的方法可以做到这一点,这对 Oracle 来说是一个真正的痛苦。他们应该只实现 LIMIT/OFFSET 子句......
rownum 在 where 子句选择行后被分配,因此 rownum 必须始终以 1 开头。where rownum > x
将始终计算为错误的。
另外,rownum 在排序完成之前被赋值,因此 rownum 的顺序将与您所说的顺序不同。
您可以使用子选择来解决这两个问题:
select a,b,c, rn from
( select a,b,c, rownum rn from
( select a,b,c from the_table where x = ? order by c)
where rownum < Y)
where rn > X
如果你不需要排序(但只有这样),你可以简化为
select a,b,c, rn from
( select a,b,c, rownum rn from the_table where rownum < Y )
where rn > X
关于sql (oracle) 选择前10条记录,然后是下10条,依此类推,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3869311/