ROW_NUMBER

Syntax

Purpose

ROW_NUMBER is an analytic function. It assigns a unique number to each row to which it is applied (either each row in the partition or each row returned by the query), in the ordered sequence of rows specified in the ORDER_BY_clause, beginning with 1.

Example

For each department in the EMP table, the following example assigns numbers to each row in order of employee's hire date:

ROW_NUMBER is a nondeterministic function. However, HIREDATE is a unique key, so the results of this application of the function are deterministic. For examples of nondeterministic behavior, see "FIRST_VALUE" and "LAST_VALUE".