如何在“选择"中添加偏移量在 Oracle 11g 中查询?

2021-12-30 00:00:00 sql oracle11g oracle pagination rownum

如何在 Oracle 11g 的选择"查询中添加偏移量.我只知道如何通过例如 rownum <= 5 添加限制这个问题不是重复的,我已经检查了其他问题并且与我的无关.

How to add an offset in a "select" query in Oracle 11g. I only know how to add the limit by e.g rownum <= 5 this question is not a duplicate, I already checked the other questions and are not related to mine.

那么,如何在 Oracle 11g 中添加偏移量?

So, how to add the offset in Oracle 11g ?

推荐答案

您可以通过指定 OFFSET12c 上轻松完成.

You can do it easily on 12c by specifying OFFSET.

12c中,

SELECT val
FROM   table
ORDER BY val
OFFSET 4 ROWS FETCH NEXT 4 ROWS ONLY;

要在 11g 及之前做同样的事情,你需要使用 ROWNUM 两次,inner queryouter query分别.

To do the same on 11g and prior, you need to use ROWNUM twice, inner query and outer query respectively.

11g 中的相同查询,

SELECT val
FROM   (SELECT val, rownum AS rnum
        FROM   (SELECT val
                FROM   table
                ORDER BY val)
        WHERE rownum <= 8)
WHERE  rnum > 4;

这里OFFSET是4.

相关文章