OceanBase logo

OceanBase

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

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

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

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.3.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    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.3.0
    iconOceanBase Database
    SQL - V 4.3.0
    SQL
    KV
    • 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

    NLSSORT

    Last Updated:2026-04-15 08:30:01  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples

    folded

    share

    Purpose

    NLSSORT() returns a collation key for given characters based on the explicitly or implicitly specified collation.

    The NLSSORT() function uses a specified collation to generate a collation key. The collation key is a byte string for sorting characters based on a specified collation.

    The length of the sort key is specified by the MAX_STRING_SIZE parameter. If MAX_STRING_SIZE=EXTENDED, the maximum length of the return value is 32,767 bytes. If the sort key exceeds the maximum length allowed, execution of the function fails and the error "unable to create the collation key" is returned.

    Syntax

    NLSSORT(char [, 'nlsparam' ])
    

    Parameters

    Parameter Description
    char This parameter supports both literals and expressions (including column names). It can be of the CHAR, VARCHAR2, NCHAR, or NVARCHAR2 data type. If the input characters are of the CLOB data type, the characters are implicitly converted.
    nlsparam Specifies the sorting rule. The fixed format of nlsparam is NLS_SORT = collation. collation refers to the language sorting rule name. Starting from OceanBase Database V4.2, a new sorting method based on the GB18030_2022 character set is now supported for simplified Chinese sorting. The collations available for simplified Chinese character sets include:
    • SCHINESE_PINYIN2_M: Sort by Pinyin.
    • SCHINESE_STROKE2_M: Sort by stroke.
    • SCHINESE_RADICAL2_M: Sort by radical.
    For Unicode, the following three simplified Chinese sorting methods are currently supported:
    • UCA0900_SCHINESE_PINYIN: Sort by Pinyin.
    • UCA0900_SCHINESE_STROKE: Sort by stroke.
    • UCA0900_SCHINESE_RADICAL: Sort first by radical, then by stroke.
    If nlsparam is omitted, this function uses the default sorting rule of the character set.

    Examples

    obclient> CREATE TABLE tbl1(PK INT, name VARCHAR(25));
    Query OK, 0 rows affected
    
    obclient> INSERT INTO tbl1 VALUES(1,'Fukesi'),(2,'Jingcha'),(3,'Dishi'),(4,'Linken'),(5,'Yalisangnazhou'),(6,'Huashengdun'),
          (7,'Daier'),(10,'Langxun');
    Query OK, 8 rows affected
    Records: 8  Duplicates: 0  Warnings: 0
    
    obclient> SELECT * FROM tbl1;
    +------+-----------------+
    | PK   | NAME            |
    +------+-----------------+
    |    1 | Fukesi          |
    |    2 | Jingcha         |
    |    3 | Dishi           |
    |    4 | Linken          |
    |    5 | Yalisangnazhou  |
    |    6 | Huashengdun     |
    |    7 | Daier           |
    |   10 | Langxun         |
    +------+-----------------+
    8 rows in set
    
    obclient> SELECT * FROM tbl1 ORDER BY NLSSORT(name,'NLS_SORT = SCHINESE_PINYIN_M');
    +------+-----------------+
    | PK   | NAME            |
    +------+-----------------+
    |    7 | Daier           |
    |    3 | Dishi           |
    |    1 | Fukesi          |
    |    6 | Huashengdun     |
    |    2 | Jingcha         |
    |   10 | Langxun         |
    |    4 | Linken          |
    |    5 | Yalisangnazhou  |
    +------+-----------------+
    8 rows in set
    

    Previous topic

    NLS_LOWER
    Last

    Next topic

    NLS_UPPER
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples