Skrevet av Emne: Oracle SQL: How limit the number of rows in a query  (Lest 4208 ganger)

ATC

  • Gjest
Oracle SQL: How limit the number of rows in a query
« på: 09. Mars 2009, 17:38 pm »
  • [applaud]0
  • [smite]0
  • I have got a query that returns thousands of rows but I'm only interested in the first 20 records. In mysql I can limit the returned data (and thus the network traffic) with the LIMIT start,number clause, where start is the starting row and number is the number of rows that I want to see.

    Is something similar possible in Oracle as well?



    ATC

    • Gjest
    [Solved] Oracle SQL: How limit the number of rows in a query
    « Svar #1 på: 09. Mars 2009, 17:38 pm »
  • [applaud]0
  • [smite]0
  • Oracle has a system attribute ROWNUM for each record returned. A query that only returns the first 20 records would look like the one in the example.

    ROWNUM starts counting with 1.

    // mysql
    select col from tbl limit 20;

    // Oracle
    select col from tbl where rownum<=20;

    // Microsoft SQL
    select top 20 col from tbl;

    Source: http://www.delphifaq.com/faq/databases/oracle/f594.shtml