Описание тега rownum
An Oracle database pseudocolumn, which returns a number indicating the order in which rows have been selected.
ROWNUM
is a pseudocolumn available in Oracle database. A pseudocolumn behaves like a table column, but is not actually stored in the table.
Questions tagged rownum should also be tagged oracle.
ROWNUM
returns a number indicating the order in which rows have been returned from a select statement. The first row selected has a ROWNUM
of 1, the second of 2 etc.
ROWNUM
can be used to restrict the rows returned from a select statement but it's important to note that an ORDER BY
is evaluated after the WHERE
clause.
This select statement will return a random 10 rows:
select *
from a_table
where rownum < 11
order by id asc
whereas this will return the first 10 IDs (a top-10 query):
select *
from ( select *
from a_table
order by id asc )
where rownum < 11
Oracle database documentation:
- ROWNUM Pseudocolumn
On ROWNUM and Limiting Results by Tom Kyte in Oracle Magazine
Frequently asked Stackru questions: