Saturday, 25 February 2017

ROWID and ROWNUM


Rownum is a pseudo column which is generated for query data set at runtime.


Rowid is the physical address of the row and hence definition suggest rowid for a row will never change but row num will always change.

Rownum is the temp num assigned for the return rows per statement query
It will change as per the query statement. 
It can be used with "=1" or "< 10" id number .

Where as Rowid is the id assigned by the  Oracle while creating record in database.  It is permanent & we can query with "=" sign & it will not change 
or depend on query.


Some more Points about Rowid and Rownum : 

1. Rowid gives address of rows or records. Rownum gives count of records.

2. Rowid is permanently stored in database. Rownum is not stored in database permanently 


3. Rowid is automatically assigned with every inserted into a table. Rownum is an dynamic value automatically 
retrieved along with select statement output.


4. It is only for display purpose.

5. ROWNUM is a pseudocolumn returning a sequential number along with the rows retrieved, whereas rowid (also a pseudo column) contains the actual physical address of the data block containing the row.



6.ROWID uniquely identifies where a row resides on disk.  The information in a ROWID gives Oracle everything it needs to find your row, the disk number, the cylinder, block and offset into the block. It actually the physical address.
ROWID can be used to fetch a row from database.
ROWID is permanent.


7. ROWNUM is a "pseudo-column", ROWNUM is used to restrict the number of rows in a query.
ROWNUM is temporary.



8. ROWID is a semi-physical value specifying the location of a row (in terms of data file, extent, etcetera). ROWID is not very useful in day-to-day programming, as it is not a constant value (it changes with table re-organizations, imports, and things like that). Therefore it requires caution in its use.


9. ROWNUM is a logical value for the sequence of row retrieval in the resultset. This is the position before sorting, so rownum is not always the same as the position in the resultset presented to you. This also requires some caution.

No comments:

Post a Comment