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

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive 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.3.5
    iconOceanBase Database
    SQL - V 4.3.5
    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

    Create a sequence

    Last Updated:2026-04-09 02:53:55  Updated
    Share
    What is on this page
    References

    folded

    Share

    In OceanBase Database, a sequence is an auto-increment sequence number generated in the database based on some rules. It is usually a set of numeric values (of the numeric data type). A sequence auto-increments and therefore is often used as a primary or unique key.

    You can use the CREATE SEQUENCE statement to create a sequence. A sequence provides two pseudo-columns: CURRVAL and NEXTVAL, which return the current sequence value and the next sequence value respectively. Each reference to NEXTVAL will update the value of CURRVAL.

    To execute this statement, you must have the CREATE privilege.

    The SQL syntax is as follows:

    CREATE SEQUENCE [IF NOT EXISTS] [database_name.]sequence_name
    [MINVALUE int_value | NOMINVALUE]
    [MAXVALUE int_value | NOMAXVALUE]
    [START WITH int_value]
    [INCREMENT BY int_value]
    [CACHE int_value | NOCACHE]
    [ORDER | NOORDER]
    [CYCLE | NOCYCLE];
    

    The parameters are described as follows:

    • IF NOT EXISTS: If the sequence to be created already exists and IF NOT EXISTS is not specified, the system returns an error. This parameter is optional.

    • database_name.: the database in which the sequence resides. This parameter is optional. If you do not specify database_name, the sequence is created in the current login database by default.

    • MINVALUE int_value | NOMINVALUE: the minimum value of the sequence. The value range is [-1027, (1027-1)].

      If NOMINVALUE is specified, the minimum value is 1 for an ascending sequence and -(1027-1) for a descending sequence.

      If MINVALUE is not specified, NOMINVALUE takes effect by default.

    • MAXVALUE int_value | NOMAXVALUE: the maximum value of the sequence. The value range is [(-1027+1), (1028-1)].

      If NOMAXVALUE is specified, the maximum value is (1028-1) for an ascending sequence, and -1 for a descending sequence.

      If MAXVALUE is not specified, NOMAXVALUE takes effect by default.

    • START WITH: the start value of the sequence. The value must be less than or equal to MAXVALUE, and greater than or equal to MINVALUE. If no start value is specified, the start value is the minimum value for an ascending sequence and the maximum value for a descending sequence.

    • INCREMENT BY: the auto-increment step of the sequence. The value cannot be 0. If the value is positive, the sequence ascends. If the value is negative, the sequence descends. If this parameter is not specified, the default value 1 takes effect.

    • CACHE: the number of sequence values that the database preallocates and keeps in memory. The default value is 20.

    • ORDER | NOORDER: specifies whether the values of the sequence are generated sequentially. ORDER indicates sequential generation, and NOORDER indicates non-sequential generation. The default value is NOORDER.

    • CYCLE | NOCYCLE: specifies whether the values of the sequence are cyclically generated. CYCLE indicates a cycling sequence, and NOCYCLE indicates a non-cycling sequence. The default value is NOCYCLE.

    Notice

    • When both MINVALUE and MAXVALUE are specified, MINVALUE must be less than MAXVALUE.
    • The difference between MAXVALUE and MINVALUE must be greater than or equal to INCREMENT BY int_value.
    • The value of CACHE must be greater than 1. If the value of CACHE INT_VALUE is 1, it is equivalent to NOCACHE.
    • If CYCLE is specified and the value of INCREMENT BY is less than 0, MINVALUE must be specified.
    • If CYCLE is specified, the number of values in the cache must be less than the number of values in the cycle.

    The following example creates the sequence seq1 and specify the auto-increment step to 2:

    obclient> CREATE SEQUENCE seq1 START WITH 1 MINVALUE 1 MAXVALUE 10 INCREMENT BY 2 NOCYCLE NOORDER CACHE 30;
    

    For more information about the CREATE SEQUENCE statement, see CREATE SEQUENCE.

    References

    For more information about operations on a sequence, see the following topics:

    • Query sequences

    • Reference a sequence

    • Modify a sequence

    • Drop a sequence

    Previous topic

    Drop a materialized view
    Last

    Next topic

    Query sequences
    Next
    What is on this page
    References