2.2.3 The ROWNUM Pseudo-Column

Table of Contents Previous Next


2 SQL Tutorial : 2.2 Advanced Concepts : 2.2.3 The ROWNUM Pseudo-Column

ROWNUM is a pseudo-column that is assigned an incremental, unique integer value for each row based on the order the rows were retrieved from a query. Therefore, the first row retrieved will have ROWNUM of 1; the second row will have ROWNUM of 2 and so on.
The ROWNUM value is assigned to each row before any sorting of the result set takes place. Thus, the result set is returned in the order given by the ORDER BY clause, but the ROWNUM values may not necessarily be in ascending order as shown in the following example:
The following example shows how a sequence number can be added to every row in the jobhist table. First a new column named, seqno, is added to the table and then seqno is set to ROWNUM in the UPDATE command.
The following SELECT command shows the new seqno values.

2 SQL Tutorial : 2.2 Advanced Concepts : 2.2.3 The ROWNUM Pseudo-Column

Table of Contents Previous Next