How do I limit the number of rows returned by an Oracle query after ordering?

前端 未结 17 1556
夕颜
夕颜 2020-11-21 04:56

Is there a way to make an Oracle query behave like it contains a MySQL limit clause?

In MySQL, I can do this:

         


        
17条回答
  •  被撕碎了的回忆
    2020-11-21 05:17

    An analytic solution with only one nested query:

    SELECT * FROM
    (
       SELECT t.*, Row_Number() OVER (ORDER BY name) MyRow FROM sometable t
    ) 
    WHERE MyRow BETWEEN 10 AND 20;
    

    Rank() could be substituted for Row_Number() but might return more records than you are expecting if there are duplicate values for name.

提交回复
热议问题