ROWNUM in Oracle is a pseudo column that represents the row sequence number in the current query result. It is mainly used for paging queries, row number display and avoiding duplicate data.
ROWNUM in Oracle
meaning
ROWNUM is Oracle A pseudo column in which represents the sequence number of rows in the current query results.
Syntax
ROWNUM is usually used with the ORDER BY clause, the syntax is as follows:
<code class="sql">SELECT column_list FROM table_name ORDER BY column_name ROWNUM <= n</code>
Where:
column_list
is the data column to be extracted table_name
is the target table column_name
is the column to be sorted by n
is the number of rows to be limited Purpose
ROWNUM is mainly used for the following purposes:
Example
Paging query:
<code class="sql">SELECT * FROM employees ORDER BY employee_id ROWNUM <= 10</code>
Line number display:
<code class="sql">SELECT ROWNUM AS row_number, * FROM employees ORDER BY employee_id</code>
Avoid duplicate data:
<code class="sql">SELECT DISTINCT employee_name FROM employees WHERE ROWNUM = 1</code>
The above is the detailed content of What is rownum in oracle. For more information, please follow other related articles on the PHP Chinese website!