Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Question: Finding the nth row in a table

Re: Question: Finding the nth row in a table

From: Allen Kirby <akirby_at_att.com>
Date: 1997/12/04
Message-ID: <3486B686.2628@att.com>#1/1

Sadhnani wrote:
>
> Dear Nguyen,
>
> Try select * from <tablename> where rownum = <n>
>
> Naresh

<snip>

I believe that will only work if n=1. If, say, n=10, then oracle will retrieve the first row from the table (at this point, rownum logically equals 1 because no rows have been returned to the user) and compare the value of rownum with the where clause, in this case 10, and it will not return the row because 1 != 10. This continues with each row and no rows will be returned. In fact, no rows will ever be returned if the rownum comparison doesn't include 1. The only way I can think of to get the Nth row is to use a cursor and stop when you get to that row. This works with sorted queries as well.

-- 
Allen Kirby			
AT&T Information Technology Services
Alpharetta, GA.
The views expressed here are mine, not my employers.
Received on Thu Dec 04 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US