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: How to select top n rows from a table?

Re: How to select top n rows from a table?

From: Kenny Gump <kgump_at_mylanlabs.com>
Date: Mon, 5 Apr 1999 15:50:40 -0400
Message-ID: <370913c1.0@news.mountain.net>


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

Original text of this message

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