inityk inityk - 1 year ago 106
SQL Question

What is rowID & rowNum (ROWID vs ROWNUM)

I'd like to know difference between


And how to see both of these in our table.

when I execute this:

SELECT * FROM emp WHERE rownum=1

It returns one query but when I do the same for rowid it says

inconsistent datatypes: expected ROWID got NUMBER

And even in some of the tables, rownum returns null . Why so?

Please clarify this: rowid vs rownum?(Demo query)

Thank you

EDIT: Require to use alias to display
(as they're pseudocolumn)

SELECT rownum r1, rowid r2 FROM emp

Answer Source

Both, rownum and rowed are pseudo columns.


For each row in the database, the ROWID pseudocolumn returns the address of the row.

An example query would be:

SELECT ROWID, last_name  
   FROM employees
   WHERE department_id = 20;

More info on rowid here:


For each row returned by a query, the ROWNUM pseudocolumn returns a number indicating the order in which Oracle selects the row from a table or set of joined rows. The first row selected has a ROWNUM of 1, the second has 2, and so on.

You can limit the amount of results with rownum like this:

SELECT * FROM employees WHERE ROWNUM < 10;

More info on rownum here:


The actual difference between rowid and rownum is, that rowid is a permanent unique identifier for that row. However, the rownum is temporary. If you change your query, the rownum number will refer to another row, the rowed won't.

So the ROWNUM is a consecutive number which applicable for a specific SQL statement only. In contrary the ROWID, which is a unique ID for a row.