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

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

    I'v started preparing for Oracle 1z0-047 exam, validated against 12c While prepping for it i came across a 12c enhancement known as 'FETCH FIRST' It enables you to fetch rows /limit rows as per your convenience. Several options are available with it

    - FETCH FIRST n ROWS ONLY
     - OFFSET n ROWS FETCH NEXT N1 ROWS ONLY // leave the n rows and display next N1 rows
     - n % rows via FETCH FIRST N PERCENT ROWS ONLY
    

    Example:

    Select * from XYZ a
    order by a.pqr
    FETCH FIRST 10 ROWS ONLY
    

提交回复
热议问题