Home » SQL & PL/SQL » SQL & PL/SQL » when a ROWNUM value is actually assigned ? (win2003)
when a ROWNUM value is actually assigned ? [message #310406] Tue, 01 April 2008 02:25 Go to next message
xzlcat
Messages: 1
Registered: April 2008
Junior Member
Recently I really confused about the rownum under the hood .

It seems Tom has already explained this clearly enough :
http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
He said:
A ROWNUM value is assigned to a row after it passes the predicate phase of the query but before the query does any sorting or aggregation. Also, a ROWNUM value is incremented only after it is assigned, which is why the following query will never return a row:

select *
from t
where ROWNUM > 1;

Because ROWNUM > 1 is not true for the first row, ROWNUM does not advance to 2. Hence, no ROWNUM value ever gets to be greater than 1.


but we know "where rownum = 1" is correct .If rownum is assigned only after passeing the predicate , then "where rownum = 1" is incorrect ,because we haven't even assign it any value .
Then when rownum = 1 is assigned ?
After select ? and only assign the first row 's ROWNUM is 1,and then waiting for the predicate clause to begain the next increment ?

Thanks !




Re: when a ROWNUM value is actually assigned ? [message #310428 is a reply to message #310406] Tue, 01 April 2008 04:26 Go to previous message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Rownum predicate is the last evaluated one, more it is not regarded as a value predicate but as an operation, so it already passed all other ones and value is assigned.
Sentence should be something like "A ROWNUM value is assigned to a row after it passes the predicate phase of the query without taking into account predicates on rownum itself" but it is obvious and will make the style heavier for nothing.

Regards
Michel
Previous Topic: Enter symbol is coming while inserting rows table into file
Next Topic: No records fetch in Cursor.
Goto Forum:
  


Current Time: Sat Dec 10 09:17:12 CST 2016

Total time taken to generate the page: 0.04467 seconds