visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: Oracle :: LIMIT clause in Oracle ?


By: tiscaliBE Belgium  Date: 28/12/2004 09:00:43  English  Points: 20 Status: Answered
Quality : Excellent
Me again ;-)

I want to restrict the results set in Oracle to prevent the client (be it TOAD or my scripts) from returning all the rowset (potentially enormous) but only the first 10 lines or so.

I know in some RDBMS you can add a "LIMIT n,m" clause at the end of the SELECT statement. This has the result of limiting the rowset to the "n to m"-th lines

How can I do this in Oracle ? This multi-million dollars system seems to be lacking such a simple&useful "enhancement" to SQL.
By: VGR Date: 29/12/2004 09:04:23 English  Type : Answer
you're right again about Oracle lacking "LIMIT"

1) for a "simple" query with a clause "LIMIT 25" (ie, the first 25 rows only), do execute this :
$sql = "select * from ($real_sql) where rownum<=25";

2) for a more complex query with a "limit 10,30" clause, use that :
$sql = "SELECT $fields FROM (SELECT rownum as db_rownum, $fields FROM ($real_sql) WHERE rownum<=30) WHERE db_rownum >=10";

Best regards and welcome in the wonderful world of "Oracle, the most powerful RDBMS in the world" :D
By: Bernard Date: 30/12/2004 08:49:25 English  Type : Comment
yes, the infamous pseudo-column "rownum" is the way to go
By: tiscaliBE Date: 30/12/2004 12:55:52 English  Type : Comment
thanks ;-)

Do register to be able to answer

EContact
browser fav
page generated in 299.423930 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page