Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: ROWNUM question??
Oscar and Aj, The problem is because Oracle assigns the rownum to the row
before the rows are passed to sort.
Example:
TRAIN> select ename from emp where rownum < 5;
ENAME
ENAME
ENAME
ENAME
TRAIN> set serveroutput on
TRAIN> declare
2 v_ename emp.ename%type;
3 cursor c_first_row is
4 select ename
5 from emp
6 order by ename;
7 begin
8 open c_first_row;
9 fetch c_first_row into v_ename;
10 close c_first_row;
11 dbms_output.put_line(v_ename);
12 end;
13 /
ADAMS
PL/SQL procedure successfully completed.
I hope this helps everyone.
Mark D. Powell
In article <7837qv$fc7$1_at_ash.prod.itd.earthlink.net>,
"Aj" <ajkumar_at_earthlink.net> wrote:
> Oracle rownum wouldnever be 1. They are long crazy numbers... Try this
> rownum < 2
>
> Aj
> Oscar Paredes wrote in message <36A4E33D.74474199_at_fib.upc.es>...
> >
> >Hi all!
> >
> >I want to select the first row of a SELECT statement
> >that have a ORDER BY, like:
> >
> > select e.name
> > from employee e
> > where rownum=1
> > order by e.name
> >
> >But,... unfortunatelly... this don't work!! :-(
> >
> >Someone know how to do this????
> >
> >
> >Thanks,
> >Oscar
-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Wed Jan 20 1999 - 08:15:53 CST