TOP 1000 in Oracle

  • I need to query a production Oracle 9i database. I will be selecting all columns from a table that has about 10 million rows.

    Unfortunately, there is not a test server available.

    How can I query for the top 1000 records (no particular order) and be sure I'm not taxing the server?

  • sqlgreg (2/7/2011)


    I need to query a production Oracle 9i database. I will be selecting all columns from a table that has about 10 million rows.

    Unfortunately, there is not a test server available.

    How can I query for the top 1000 records (no particular order) and be sure I'm not taxing the server?

    Oracle does not supports "TOP" syntax.

    For random rows with no particular order...

    select mycolumn

    from mytable

    where rownum < 1000;

    If you want columns sorted...

    select * from (

    select mycolumn

    from mytable

    order by mycolumn)

    where rownum < 1000;

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • I was just about the post the answer when I saw your reply! Thanks!

    I didn't know what to search for in the Oracle documentation.

  • sqlgreg (2/7/2011)


    I was just about the post the answer when I saw your reply! Thanks!

    I didn't know what to search for in the Oracle documentation.

    That's why God created forums 😀

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Oracle has a very good documentation and excellent site that answers your even the toughest questions in detail by a true Oracle master: Thomas Kyte http://asktom.oracle.com

    Top N question was piece-of-cake, complete beginner's question.

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • Vedran Kesegic (3/7/2011)


    Top N question was piece-of-cake, complete beginner's question.

    I'm failing to see the value of this particular post.

    Also, why you have to be rude to the original poster?

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Dear sqlgreg, Sorry, I didn't mean to be rude. Just wanted to point out that asktom.com has profound answers on even the most complicated questions. Maybe I expressed that in a wrong way. I apologize sincerely and thanky you PaulB that you made me aware of that.

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths
  • Thanks, Paul, and no problem, Vedran.

    I agree that asktom.oracle.com is quite helpful; I found that site quite useful when I was working with Oracle last month.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply