方法1:利用ROW_NUMBER函数
SELECT NO FROM (
SELECT ROW_NUMBER() OVER (ORDER BY NO) RNO, NO FROM ROWNUM_TEST
)
WHERE RNO <= 5
ORDER BY NO ;
SELECT ROW_NUMBER() OVER (ORDER BY NO) RNO, NO FROM ROWNUM_TEST
)
WHERE RNO <= 5
ORDER BY NO ;
取出中间 n 条记录
SELECT NO FROM (
SELECT ROW_NUMBER() OVER (ORDER BY NO) RNO, NO FROM ROWNUM_TEST
)
WHERE RNO BETWEEN 5 AND 10
ORDER BY NO;
SELECT ROW_NUMBER() OVER (ORDER BY NO) RNO, NO FROM ROWNUM_TEST
)
WHERE RNO BETWEEN 5 AND 10
ORDER BY NO;
方法2:利用子查询
SELECT NO FROM (
SELECT NO FROM ROWNUM_TEST
ORDER BY NO
)
WHERE ROWNUM <= 5
ORDER BY NO ;
SELECT NO FROM ROWNUM_TEST
ORDER BY NO
)
WHERE ROWNUM <= 5
ORDER BY NO ;
取出中间 n 条记录
SELECT NO FROM (
SELECT NO, ROWNUM RNO FROM (
SELECT NO FROM ROWNUM_TEST
ORDER BY NO
)
) WHERE RNO BETWEEN 5 AND 10
ORDER BY NO;
SELECT NO, ROWNUM RNO FROM (
SELECT NO FROM ROWNUM_TEST
ORDER BY NO
)
) WHERE RNO BETWEEN 5 AND 10
ORDER BY NO;