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

    INSERT

    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 add one or more records to a table.

    Direct INSERT operations on subqueries are not supported. For example, INSERT INTO (SELECT * FROM t1) VALUES(1, 1) cannot be executed.

    Syntax

    INSERT [IGNORE] [INTO]
           single_table_insert
           [ON DUPLICATE KEY UPDATE update_asgn_list]
    
    single_table_insert:
        {dml_table_name values_clause
         | dml_table_name '(' ')' values_clause
         | dml_table_name '(' column_list ')' values_clause
         | dml_table_name SET update_asgn_list}
    
    dml_table_name:
        table_name [PARTITION (partition_name,...)]
    
    values_clause:
         {{VALUES | VALUE} ({expr | DEFAULT},...) [, ...]
          | select_stmt}
    
    column_list
        column_name [, ...]
    
    update_asgn_list:
         column_name = expr [, ...]
    

    Parameters

    Parameter
    Description
    IGNORE Ignores errors that occur during the execution of an INSERT statement.
    column_list The name of the column to which the data is inserted. Multiple columns must be separated with commas (,).
    table_name The name of the table into which data is to be inserted.
    partition_name The name of the partition into which data is to be inserted.
    update_asgn_list The statement that assigns values such as c1 = 2.
    ON DUPLICATE KEY UPDATE The action performed on duplicate primary keys or unique keys. If this parameter is specified, the configured value takes the place of the inserted value when the inserted primary key or unique key is duplicated. If this parameter is not specified, an error is returned when the inserted primary key or unique key is duplicated.

    Examples

    Sample tables and their data are defined as follows:

    obclient> CREATE TABLE t1(c1 INT PRIMARY KEY, c2 INT) PARTITION BY KEY(c1) PARTITIONS 4;
    Query OK, 0 rows affected
    
    obclient> CREATE TABLE t2(c1 INT PRIMARY KEY, c2 INT);
    Query OK, 0 rows affected
    obclient> SELECT * FROM t2;
    +----+------+
    | c1 | c2   |
    +----+------+
    |  1 |    1 |
    |  2 |    2 |
    |  3 |    3 |
    |  4 |    4 |
    +----+------+
    4 rows in set
    
    • Insert a row of data into table t1.

      obclient>  INSERT INTO t1 VALUES(1,1);
      Query OK, 1 row affected
      
      obclient> SELECT * FROM t1;
      +----+------+
      | c1 | c2   |
      +----+------+
      |  1 |    1 |
      +----+------+
      1 row in set
      
    • Insert multiple rows of data into table t1.

      obclient> INSERT t1 VALUES(1,1),(2,DEFAULT),(2+2,3*4);
      Query OK, 3 rows affected
      Records: 3  Duplicates: 0  Warnings: 0
      
      obclient> SELECT * FROM t1;
      +----+------+
      | c1 | c2   |
      +----+------+
      |  1 |    1 |
      |  2 | NULL |
      |  4 |   12 |
      +----+------+
      3 rows in set
      
    • Insert a single row of data into partition p0 of table t1.

      obclient> INSERT INTO t1 PARTITION(p0) (c1) VALUES(5);
      Query OK, 1 row affected
      obclient> SELECT * FROM t1 PARTITION(p0);
      +----+------+
      | c1 | c2   |
      +----+------+
      |  5 | NULL |
      +----+------+
      1 row in set
      
    • When you insert a duplicate primary key value into table t1, use the ON DUPLICATE KEY UPDATE function to update the value.

      obclient> INSERT INTO t1 VALUES(1,1),(1,2) ON DUPLICATE KEY UPDATE c1=100;
      Query OK, 3 rows affected
      Records: 2  Duplicates: 1  Warnings: 0
      
      obclient> SELECT * FROM t1;
      +-----+------+
      | c1  | c2   |
      +-----+------+
      | 100 |    1 |
      +-----+------+
      1 row in set
      
    • Insert values into an updatable view v.

      obclient> CREATE VIEW v AS SELECT * FROM t1;
      Query OK, 0 rows affected
      obclient> INSERT INTO v VALUES (1,1);
      Query OK, 1 row affected
      
      obclient> SELECT * FROM v;
      +----+------+
      | c1 | c2   |
      +----+------+
      |  1 |    1 |
      +----+------+
      1 row in set
      
    • Insert the query results of table t1 into table t2.

      obclient> INSERT INTO t1 SELECT * FROM t2 WHERE c1>2;
      Query OK, 2 rows affected
      Records: 2  Duplicates: 0  Warnings: 0
      
      obclient> SELECT * FROM t1;
      +----+------+
      | c1 | c2   |
      +----+------+
      |  3 |    3 |
      |  4 |    4 |
      +----+------+
      2 rows in set
      

    Previous topic

    HELP
    Last

    Next topic

    KILL
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples