Home > Database > Oracle > body text

What is rownum in oracle

下次还敢
Release: 2024-05-02 23:27:53
Original
1206 people have browsed it

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.

What is rownum in oracle

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>
Copy after login

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:

  • Paging query: By limiting the value of ROWNUM, paging query can be implemented, so that only a part of the data can be retrieved at a time.
  • Row number display: Display the sequence number of the row in the query results.
  • Avoid duplicate data: In some cases, ROWNUM can help avoid duplicate data in query results.

Example

Paging query:

<code class="sql">SELECT *
FROM employees
ORDER BY employee_id
ROWNUM <= 10</code>
Copy after login

Line number display:

<code class="sql">SELECT ROWNUM AS row_number, *
FROM employees
ORDER BY employee_id</code>
Copy after login

Avoid duplicate data:

<code class="sql">SELECT DISTINCT employee_name
FROM employees
WHERE ROWNUM = 1</code>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!