Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to select top n rows from a table?
Not real sure about straight SQL, but using PL/SQL:
declare
2 cursor mytc is
3 select username from dba_users order by username;
4 v_user dba_users.username%type;
5 begin
6 open mytc;
7 for i in 1..10 loop
8 fetch mytc into v_user;
9 dbms_output.put_line('User ' || to_char(i, 99) || ' = ' || v_user);
10 end loop;
11 close mytc;
12* end;
Will give you the desired results.
Kenny Gump
xiebl_at_usa.net wrote in message <7eabqp$joc$1_at_nnrp1.dejanews.com>...
>Hi, everyone I'd like to select the first n rows of a table according to
>some reasons. For instance, I need to select the top 10 students with best
>scores in a class, by applying just one SQL statement. In fact, my C/S
>environment cannot stand the network traffic if I cannot do that neatly at
>the server end. I find Oracle privides ROWNUM psuedocolumn but the ORDER
BY
>clause cannot be used in any subqueries. Do you know how to solve this
>problem? Please give me a hand.
>
>Xie Binglong
>Image Processing Group, Tsinghua University
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Received on Mon Apr 05 1999 - 14:50:40 CDT
![]() |
![]() |