ROWNUM:Row Numbers

ROWNUM returns the row number in a result set. The first row returned by a query has a row number of 1.


CREATE TABLE EMP (EMPNO NUMBER(4) NOT NULL,
                      ENAME VARCHAR2(10),
                      HIREDATE DATE);

INSERT INTO EMP VALUES (1, 'SMITH', TO_DATE('17-DEC-1980', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (2, 'ALLEN', TO_DATE('20-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (3, 'WARD',  TO_DATE('22-FEB-1981', 'DD-MON-YYYY'));
INSERT INTO EMP VALUES (4, 'JONES', TO_DATE('2-APR-1981',  'DD-MON-YYYY'));
INSERT INTO EMP VALUES (5, 'MARTIN',TO_DATE('28-SEP-1981', 'DD-MON-YYYY'));

SQL> SELECT ROWNUM, empno, ename FROM Emp;

    ROWNUM      EMPNO ENAME
---------- ---------- ----------
         1          1 SMITH
         2          2 ALLEN
         3          3 WARD
         4          4 JONES
         5          5 MARTIN

SQL>

ROWNUM and where clause:


SQL> SELECT ROWNUM, empno, ename FROM Emp
  2  WHERE empno = 3;

    ROWNUM      EMPNO ENAME
---------- ---------- ----------
         1          3 WARD

SQL>
Home »
Oracle »
Select » 

Simple Select:
  1. Simple select statement
  2. Retrieve date type information from a table
  3. Retrieving All Columns from a Table
  4. ROWID:Row Identifiers
  5. ROWNUM:Row Numbers
  6. Arithmetic calculation
  7. Date Arithmetic
  8. Column Arithmetic
  9. Column Aliases
  10. Combining Column Using Concatenation
  11. distinct rows
Related: