WHERE RECNO BETWEEN M AND (M + X - 1)
同样以上面的数据为例,则抽取NAME的字母顺的第2条记录开始的3条记录的SQL语句为:
SELECT ID, NAME FROM
(
SELECT ROWNUM RECNO, ID, NAME FROM
(SELECT * FROM CUSTOMER ORDER BY NAME)
WHERE ROWNUM <= (2 + 3 - 1)
ORDER BY ROWNUM ASC
)
WHERE RECNO BETWEEN 2 AND (2 + 3 - 1)
结果如下:
ID NAME
05 fifth
01 first
04 forth
以此为基础,再扩展的话,做成存储过程,将开始记录数以及抽取记录数为参数,就可以轻松实现分页抽取数据。