rownum

download rownum

If you can't read please download the document

description

rownum example

Transcript of rownum

Concept of ROWNUM, Why ROWNUM=2 gives "no rows selectedROWNUM is a psuedocolumn , its value is not predefined in a table. A number is assigned in the form of 1,2,3,...N to every row returned by a query when its executed, that number is called as ROWNUM. Its generated dynamically.Example :- Consider a table having 5 rows. PFB output of below select queries :-1. SQL> select * from amit; ID NAME---------- ------------------------------------ 1 2 3 4 52. SQL> select * from amit where rownum=1; ID NAME---------- ------------------------------------ 13. SQL> select * from amit where rownum select * from amit where rownum=2;no rows selected5. SQL> select * from amit where rownum>2;no rows selectedWe see that when we use Rownum in Where clause then it gives output only for rownum2 it gives output as "no rown selected". Reason for this behaviour of rownum is that its value is not predefined. when a select query fetch some output then a number is assingned in the form of 1,2,3...N to all rows fetched by query.First selected row is always assigned as rownum=1.Rownum value is incremented after a query passes the where clause.So when we use rownum=1 or rownum