Oracle Database Get first N rows with row limiting clause


Example

The FETCH clause was introduced in Oracle 12c R1:

SELECT   val
FROM     mytable
ORDER BY val DESC
FETCH FIRST 5 ROWS ONLY;

An example without FETCH that works also in earlier versions:

SELECT * FROM (
   SELECT   val
   FROM     mytable
   ORDER BY val DESC
) WHERE ROWNUM <= 5;