## Syntax
```mermaid
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
Start((START)) --> RANK[RANK]:::quoted
RANK --> End((END))
```
## Purpose
The `RANK` SQL function assigns a ranking number to each row based on the value of an expression. Separate ranking sequences can be introduced by partitioning on a key.
Rows with the same value receive the same rank. The next different value receives the next consecutive rank, while leaving gaps for duplicates of the same value. Rankings are calculated within each partition when a partition is specified.
See also [[ROW_NUMBER]] for numbering rows and [[DENSE_RANK]] for ranking without leaving gaps in the ranking.
Parameters:
- Current value expression (`ANY`): the expression whose values are to be ranked.
- Partition key (`varchar2`): the partition key.
Returns: the rank as `int32`.
## Examples
The following example retrieves the rank for each value without partitioning:
```sql
select c
, dense_rank(c, null)
from csvtable
( passing 'a,a,b,c'
row delimiter ','
column delimiter '#'
columns c varchar2 position next
)
-------------------
a 1
a 1
b 2
c 3
```
The following example retrieves the rank per partitioned group:
```sql
select c
, grp
, dense_rank(c, grp)
from csvtable
( passing 'a#GRP1,a#GRP1,a#GRP2,b#GRP1,c#GRP1,c#GRP2'
row delimiter ','
column delimiter '#'
columns c varchar2 position next
, grp varchar2 position next
)
-------------------
a GRP1 1
a GRP1 1
a GRP2 1
b GRP1 2
c GRP1 3
c GRP2 2
```