Home » SQL & PL/SQL » SQL & PL/SQL » Rownum
Rownum [message #241663] Wed, 30 May 2007 06:14 Go to next message
shahnazurs
Messages: 240
Registered: June 2005
Location: India
Senior Member
when i run

select * from emp
where rownum=1;

it is giving result...

when i say

select * from emp
where rownum=2;

no row(s) selected

Why?

Thanks.
Re: Rownum [message #241666 is a reply to message #241663] Wed, 30 May 2007 06:20 Go to previous messageGo to next message
tahpush
Messages: 961
Registered: August 2006
Location: Stockholm/Sweden
Senior Member

Search the board this has been discussed several times.
Also you have the Oracle Documentation as a resource.
ROWNUM

Also you have a very good article by Tom Kyte which explains rownum very nicely in detail.

[Updated on: Wed, 30 May 2007 06:24]

Report message to a moderator

Re: Rownum [message #241670 is a reply to message #241666] Wed, 30 May 2007 06:32 Go to previous messageGo to next message
shahnazurs
Messages: 240
Registered: June 2005
Location: India
Senior Member
Thanks a lot, it is very helpful.
Re: Rownum [message #242617 is a reply to message #241663] Mon, 04 June 2007 06:14 Go to previous messageGo to next message
parthokonar
Messages: 17
Registered: September 2006
Location: india
Junior Member
Actually rownum is pseudocolum. It does not really exist. After processing of the statement it is provided. it does not work with = sign. <, > works. 1 is taken as default.

Re: Rownum [message #242623 is a reply to message #242617] Mon, 04 June 2007 06:27 Go to previous messageGo to next message
Michel Cadot
Messages: 64151
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
1 is taken as default

Is taken as default of what?
Quote:
it does not work with = sign

This is wrong, if you say it like this:
SQL> select ename from emp where rownum=1;
ENAME
----------
SMITH

1 row selected.

Quote:
> works

This is wrong, if you say it like this:
SQL> select * from emp where rownum>2;

no rows selected

Simply because there is no "rownum>2" if there is no "rownum=1" and there is no "rownum=1" as you exclude it.

Regards
Michel
Re: Rownum [message #242661 is a reply to message #242623] Mon, 04 June 2007 10:32 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
> does work.
Try > 0

This works in the same way as "=" works.
Re: Rownum [message #242665 is a reply to message #242661] Mon, 04 June 2007 11:12 Go to previous message
Michel Cadot
Messages: 64151
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Frank,

I did not say it never works.
I said it is false to say it always works which implies the sentence "> works" and I gave counter-examples of the sentences.
Just that no more no less.

Regards
Michel
Previous Topic: 3 updates fail, 1 does not. Why?
Next Topic: IF or CASE
Goto Forum:
  


Current Time: Sat Dec 10 00:56:27 CST 2016

Total time taken to generate the page: 0.08225 seconds