DENSE_RANK function in Oracle

DENSE_RANK is one of the vital Analytic functions of Oracle. It is used to get the rank of a row in a group of rows. It always results in the consecutive ranking of the rows. The DENSE_RANK function is supported in the various versions of the Oracle/PLSQL, including, Oracle 12c, Oracle 11g, Oracle 10g and Oracle 9i.


DENSE_RANK ( expr_1, expr_2, .. expr_n ) WITHIN GROUP ( ORDER BY expr_1, expr_2, .. expr_n  )

expr_1, expr_2, .. expr_n:
They are used to specify the expressions to be used for identifying a unique row in the group.


select DENSE_RANK(100, 20) WITHIN GROUP (ORDER BY marks, extra)
from students;

Here, the dense rank of a student with a total marks of 100 and an extra marks of 20 from within the students table will be returned.

Please Share