Definition:
In Oracle PL/SQL, a ROWNUM is a pseudocolumn which indicates the row number in a result set retrieved by a SQL query. It starts by assigning 1 to the first row and increments the ROWNUM value with each subsequent row returned. A query result set can be limited by filtering with the ROWNUM keyword in the WHERE clause.
Note that a ROWNUM is not data in the database or table. It has no relationship to anything in the database, including tables, tablespaces, data files, or to the order in which a row is inserted into a table. A ROWNUM is the number of a row selected from a table and will change depending on the order in which rows are selected.
Example Usage:
The SQL query below uses ROWNUM to retrieve only the first 4 records from the EMP table:
SELECT ROWNUM, DEPTNO, ENAME, SAL FROM EMP
WHERE ROWNUM < 5
/
ROWNUM DEPTNO ENAME SAL
---------- ---------- ------ ----------
1 100 JOHN 2300
2 110 MILLER 3900
3 120 KATE 4500
4 100 TIM 4200
Related Links: