RRN

The RRN function returns the relative record number of a row.

Read syntax diagramSkip visual syntax diagramRRN (table-designator)
table-designator
A table designator that could be used to qualify a column in the same relative location in the SQL statement as the RRN function. For more information about table designators, see Table designators.

In SQL naming, the table name may be qualified. In system naming, the table name cannot be qualified.

The table-designator must not identify a collection-derived-table, Start of changea VALUES clause, a table-function, or a data-change-table-reference.End of change Start of changeIf the argument identifies a view, common table expression, or nested table expression, its outer subselect must directly or indirectly reference a table. End of change

If the argument identifies a view, common table expression, or nested table expression, the function returns the relative record number of its base table. If the argument identifies a view, common table expression, or nested table expression derived from more than one base table, the function returns the relative record number of the first table in the outer subselect of the view, common table expression, or nested table expression.

If the argument identifies a distributed table, the function returns the relative record number of the row on the node where the row is located. If the argument identifies a partitioned table, the function returns the relative record number of the row in the partition where the row is located. This means that RRN will not be unique for each row of a partitioned or distributed table.

The argument must not identify a view, common table expression, or nested table expression whose outer fullselect includes an aggregate function, a GROUP BY clause, a HAVING clause, a UNION, INTERSECT, Start of changeor EXCEPTEnd of change clause, a DISTINCT clause, a VALUES clause, or a table-function. The RRN function cannot be specified in a SELECT clause if the fullselect contains an aggregate function, a GROUP BY clause, or a HAVING clause.

The data type of the result is a decimal with precision 15 and scale 0. The result can be null.

Example

  • Return the relative record number and employee name from table EMPLOYEE for those employees in department 20.
      SELECT RRN(EMPLOYEE), LASTNAME
        FROM EMPLOYEE
        WHERE DEPTNO = 20