Is there a way to make an Oracle
query behave like it contains a MySQL limit
clause?
In MySQL
, I can do this:
If you are not on Oracle 12C, you can use TOP N query like below.
SELECT *
FROM
( SELECT rownum rnum
, a.*
FROM sometable a
ORDER BY name
)
WHERE rnum BETWEEN 10 AND 20;
You can even move this from clause in with clause as follows
WITH b AS
( SELECT rownum rnum
, a.*
FROM sometable a ORDER BY name
)
SELECT * FROM b
WHERE rnum BETWEEN 10 AND 20;
Here actually we are creating a inline view and renaming rownum as rnum. You can use rnum in main query as filter criteria.