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

    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.2.2
    iconOceanBase Database
    SQL - V 4.2.2
    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 SEQUENCE

    Last Updated:2026-04-15 08:27:15  Updated
    Share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples

    folded

    Share

    Purpose

    You can use this statement to create a sequence. A sequence is a database object. You can generate a unique integer from a sequence.

    If two users increment the same sequence concurrently, the sequence numbers obtained by the two users have an interval. One user can never obtain the sequence number generated by the other user. Sequence numbers are generated independently of the table. Therefore, you can use the same sequence for multiple tables.

    After creating a sequence, you can use the CURRVAL pseudocolumn to return the current sequence value or use the NEXTVAL pseudocolumn to return the new increment value in the SQL statement. For more information, see Sequence pseudocolumns.

    Syntax

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

    Parameters

    Parameter
    Description
    schema. The schema where the sequence resides. If this parameter is not specified, the database creates the sequence in the schema of the current user.
    sequence_name The name of the sequence to be created.
    IF NOT EXISTS If the sequence name already exists and IF NOT EXISTS is not specified, an error is returned.
    MINVALUE int_value The minimum value of the sequence. Value range of int_value: [-(1027-1), (1027-1)].
    NOMINVALUE NOMINVALUE is the default value. If NOMINVALUE is specified, the minimum value is 1 for an ascending sequence and -(1027-1) for a descending sequence.
    MAXVALUE int_value The maximum value of the sequence. Value range of int_value: [(-1027+1), (1028-1)].
    Notice
    • When MINVALUE and MAXVALUE are both specified, MINVALUE must be smaller than MAXVALUE.
    • The difference between MAXVALUE and MINVALUE must be greater than or equal to INCREMENT BY int_value.
    NOMAXVALUE NOMAXVALUE is the default value. If NOMAXVALUE is specified, the maximum value is (1028-1) for an ascending sequence and -1 for a descending sequence.
    START WITH int_value The start value of the sequence. int_value must be smaller 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 int_value The increment of the sequence. int_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 is 1.
    CACHE int_value The number of sequence values pre-allocated in the memory. By default, int_value is 20. The value of CACHE int_value must be greater than 1. If the value of CACHE int_value is 1, it is equivalent to NOCACHE.
    NOCACHE Specifies that no sequence values are pre-allocated. If neither CACHE nor NOCACHE is specified, the database caches 20 sequence values by default.
    ORDER Specifies that sequence values are generated in order.
    NOORDER NOORDER is the default value, which means it is not assured that sequence values are generated in order.
    CYCLE Specifies that sequence values are generated cyclically. That is, when the sequence reaches its maximum or minimum value, new sequence values will also be generated. If the sequence ascends and reaches its maximum value, the minimum sequence value will be generated. If the sequence descends and reaches its minimum value, the maximum sequence value will be generated.
    Notice
    • If CYCLE is specified and the value of INCREMENT BY int_value is smaller than 0, MINVALUE must be specified.
    • If CYCLE is specified, the number of values in the cache cannot be greater than the number of values in the cycle.

    NOCYCLE NOCYCLE is the default value. If it is specified, no more values are generated when the sequence reaches its maximum or minimum value.

    Examples

    Create a sequence named seq1 in the test schema and set the increment to 2. In the following example, 1 is returned for the first reference to seq1.nextval, and 3 is returned for the second reference. The return value of each subsequent reference is greater than that of the previous reference by 2.

    obclient> CREATE SEQUENCE test.seq1 START WITH 1 MINVALUE 1 MAXVALUE 10 INCREMENT BY 2 NOCYCLE NOORDER CACHE 30;
    Query OK, 0 rows affected
    
    obclient> SELECT seq1.nextval FROM DUAL;
    +--------+
    | nextval|
    +--------+
    | 1      |
    +--------+
    1 row in set
    
    obclient> SELECT seq1.nextval FROM DUAL;
    +--------+
    | nextval|
    +--------+
    | 3      |
    +--------+
    1 row in set
    

    Previous topic

    DROP RESTORE POINT
    Last

    Next topic

    CREATE TABLE
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples