ROW_NUMBER
Syntax
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart LR
Start((START)) --> ROW_NUMBER[ROW_NUMBER]:::quoted
ROW_NUMBER --> End((END))
Purpose
The ROW_NUMBER SQL function calculates a consecutive row number. Separate row number sequences can be introduced by partitioning on a key.
See also DENSE_RANK for ranking without gaps in the ranking and RANK for ranking while leaving gaps in the ranking for duplicate values.
Parameters:
- Partition key (optional,
varchar2): the partition key. Defaults to'', placing all rows in a single partition.
Returns: the row number as int32.
Examples
The following example retrieves the row number for each value without partitioning:
select rge.value
, row_number(null)
from range@DataDictionary(6) rge
-------------------
1 1
2 2
3 3
4 4
5 5
6 6
The following example retrieves the row number per partitioned group:
select round(rge.value / 2) grp
, rge.value
, row_number(round(rge.value / 2))
from range@DataDictionary(6) rge
-------------------
1 1 1
1 2 2
2 3 1
2 4 2
3 5 1
3 6 2