OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.1
    iconOceanBase Database
    SQL - V 4.2.1
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    ROW_NUMBER

    Last Updated:2026-04-28 09:23:26  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples

    folded

    Share

    Purpose

    ROW_NUMBER() is an analytic function. It returns a unique sequence number for each row (group) record. The sequence numbers are sorted by the column specified in order_by_clause, starting from 1. When the same data records are found, the data records are sorted in ascending order based on the sequence of records in the recordset.

    Syntax

    ROW_NUMBER( ) OVER ([ query_partition_clause ] order_by_clause)
    

    Parameters

    You can use the OVER clause to define a window over the data on which the function operates. For more information, see Analytic functions.

    Return type

    This function returns values of a numeric data type.

    Examples

    The table emp_msg has been created. Query the emp_msg table. Group the data records in the table by the deptno field and sort the data records by the sal column in descending order. Return the ordinal number of each value in the sal column.

    obclient> SELECT * FROM emp_msg;
    +--------+--------+------+------+
    | DEPTNO | ENAME  | SAL  | MGR  |
    +--------+--------+------+------+
    |     10 | CLARK  | 2750 | 7839 |
    |     10 | KING   | 5300 | NULL |
    |     10 | MILLER | 1600 | 7782 |
    |     20 | ADAMS  | 1400 | 7788 |
    |     20 | FORD   | 3300 | 7566 |
    |     20 | JONES  | 3275 | 7839 |
    |     20 | SCOTT  | 3300 | 7566 |
    |     20 | SMITH  | 1100 | 7902 |
    |     30 | ALLEN  | 1900 | 7698 |
    |     30 | BLAKE  | 3150 | 7839 |
    |     30 | JAMES  | 1250 | 7698 |
    |     30 | MARTIN | 1550 | 7698 |
    |     30 | TURNER | 1800 | 7698 |
    |     30 | WARD   | 1550 | 7698 |
    |     30 | SCLARK | 1750 | 7839 |
    +--------+--------+------+------+
    15 rows in set
    
    obclient> SELECT deptno,ename,sal,
                     ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY sal DESC)
              FROM emp_msg;
    +--------+--------+------+---------------------------------------------------+
    | DEPTNO | ENAME  | SAL  | ROW_NUMBER()OVER(PARTITIONBYDEPTNOORDERBYSALDESC) |
    +--------+--------+------+---------------------------------------------------+
    |     10 | KING   | 5300 |                                                 1 |
    |     10 | CLARK  | 2750 |                                                 2 |
    |     10 | MILLER | 1600 |                                                 3 |
    |     20 | FORD   | 3300 |                                                 1 |
    |     20 | SCOTT  | 3300 |                                                 2 |
    |     20 | JONES  | 3275 |                                                 3 |
    |     20 | ADAMS  | 1400 |                                                 4 |
    |     20 | SMITH  | 1100 |                                                 5 |
    |     30 | BLAKE  | 3150 |                                                 1 |
    |     30 | ALLEN  | 1900 |                                                 2 |
    |     30 | TURNER | 1800 |                                                 3 |
    |     30 | SCLARK | 1750 |                                                 4 |
    |     30 | MARTIN | 1550 |                                                 5 |
    |     30 | WARD   | 1550 |                                                 6 |
    |     30 | JAMES  | 1250 |                                                 7 |
    +--------+--------+------+---------------------------------------------------+
    15 rows in set
    

    Previous topic

    REGR_(Linear Regression)
    Last

    Next topic

    STDDEV
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples