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

前端 未结 17 1467
夕颜
夕颜 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:25

    select * FROM (SELECT 
       ROW_NUMBER() OVER (ORDER BY sal desc),* AS ROWID, 
     FROM EMP ) EMP  where ROWID=5
    

    greater then values find out

    select * FROM (SELECT 
           ROW_NUMBER() OVER (ORDER BY sal desc),* AS ROWID, 
         FROM EMP ) EMP  where ROWID>5
    

    less then values find out

    select * FROM (SELECT 
           ROW_NUMBER() OVER (ORDER BY sal desc),* AS ROWID, 
         FROM EMP ) EMP  where ROWID=5
    

提交回复
热议问题