Re: Limitting number of rows returned from a select.

From: Robert Cordingley <cord_at_zoom.com>
Date: 1996/06/17
Message-ID: <31C5F8DA.4F94_at_zoom.com>#1/1


> select * from <table_name>
> where ROWNUM < 200 .
>
> This will return the first 200 rows.
> I'm pretty sure this functionality is supported in all versions subsequent to 7.0 (including 7.0).
> I think v6 also supports this.
>
> However your customer needs to keep in mind that conditions testing for ROWNUM values greater than 1 are
> always false and will not return any rows.

Also bear in mind that the 200 rows returned will be the first 200 *selected*. This is prior to any order by clauses. If there is an index and the optimizer chooses the index, then they will appear in index order. If there's no index or the optimizer chooses to ignore the index, then they'll appear in "storage" order. Strange things can happen with rownum, but it's great for guaranteeing a single row return (like when some putz with the system password inserts a row into dual). You can do something like "select user from sys.dual where rownum = 1" to guarantee that you'll get what you're expecting.

                                        Robert Received on Mon Jun 17 1996 - 00:00:00 CEST

Original text of this message