在 Oracle 12c之前
取得前 5筆資料
select * from (
select O_ID, O_NAME from TABLE_A
order by O_ID desc
)
where ROWNUM <= 5;
取得第 6 ~ 8 筆資料
select * from (
select ROWNUM as SEQ_NO, O_ID, O_NAME from (
select O_ID, O_NAME from TABLE_A
order by O_ID desc
)
)
where SEQ_NO between 6 and 8;
Oracle 12c SQL 新增了 ROW Limiting 功能
取得前 5筆資料
select O_ID, O_NAME from TABLE_A
order by O_ID desc
fetch first 5 rows;
取得第 6 ~ 8 筆資料
select O_ID, O_NAME from TABLE_A
order by O_ID desc
offset 5 rows
fetch first 3 rows only;
沒有留言:
張貼留言