Tuesday, 28 January 2014

Difference between ROWNUM and ROW_NUMBER?


 
ted
ROWNUM is a "pseudocolumn" that assigns a number to each row returned by a query:
SQL>selectrownum, ename, deptno
2fromemp;
 
    ROWNUM ENAME          DEPTNO
---------- ---------- ----------
1 SMITH              99
2 ALLEN              30
3 WARD               30
4 JONES              20
5 MARTIN             30
6 BLAKE              30
7 CLARK              10
8 SCOTT              20
9 KING               10
10 TURNER             30
11 FORD               20
12 MILLER             10
ROW_NUMBER is an analytic function that assigns a number to each row according to its ordering within a group of rows:
SQL>selectename, deptno, row_number() over (partitionbydeptnoorderbyename) rn
2fromemp;
 
ENAME          DEPTNO         RN
---------- ---------- ----------
CLARK              101
KING               102
MILLER             103
FORD               201
JONES              202
SCOTT              203
ALLEN              301
BLAKE              302
MARTIN             303
TURNER             304
WARD               305
SMITH              991
 

No comments:

Post a Comment