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

    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.3.3
    iconOceanBase Database
    SQL - V 4.3.3
    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

    Basic SQL operations (Oracle mode)

    Last Updated:2024-12-02 03:48:29  Updated
    Share
    What is on this page
    Table operations
    Create a table
    Modify a table
    Drop a table
    Index operations
    Create indexes
    Query indexes
    Drop an index
    Insert data
    Delete data
    Update data
    Query data
    Commit a transaction
    Roll back a transaction

    folded

    Share

    This topic describes the basic SQL operations in OceanBase Database in Oracle mode.

    Applicability

    This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.

    Table operations

    This section describes how to create, view, modify, and drop database tables.

    Create a table

    You can execute the CREATE TABLE statement to create a table in a database.

    For example, create a table named test.

    obclient> CREATE TABLE test (c1 INT PRIMARY KEY, c2 VARCHAR(3));
    Query OK, 0 rows affected
    

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

    Modify a table

    You can execute the ALTER TABLE statement to modify the structure of an existing table, including modifying the table name and table attributes, adding columns, modifying the column name and attributes, and dropping columns.

    Here are some examples:

    • Modify the field type of c2 in the test table.

      obclient> DESCRIBE test;
      +-------+-------------+------+-----+---------+-------+
      | FIELD | TYPE        | NULL | KEY | DEFAULT | EXTRA |
      +-------+-------------+------+-----+---------+-------+
      | C1    | NUMBER(38)  | NO   | PRI | NULL    | NULL  |
      | C2    | VARCHAR2(3) | YES  | NULL| NULL    | NULL  |
      +-------+-------------+------+-----+---------+-------+
      2 rows in set
      
      obclient> ALTER TABLE test MODIFY c2 CHAR(10);
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+------------+------+-----+---------+-------+
      | FIELD | TYPE       | NULL | KEY | DEFAULT | EXTRA |
      +-------+------------+------+-----+---------+-------+
      | C1    | NUMBER(38) | NO   | PRI | NULL    | NULL  |
      | C2    | CHAR(10)   | YES  | NULL| NULL    | NULL  |
      +-------+------------+------+-----+---------+-------+
      2 rows in set
      
    • Add a column to and drop a column from the test table.

      obclient> ALTER TABLE test ADD c3 int;
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+------------+------+-----+---------+-------+
      | FIELD | TYPE       | NULL | KEY | DEFAULT | EXTRA |
      +-------+------------+------+-----+---------+-------+
      | C1    | NUMBER(38) | NO   | PRI | NULL    | NULL  |
      | C2    | CHAR(10)   | YES  | NULL | NULL    | NULL  |
      | C3    | NUMBER(38) | YES  | NULL | NULL    | NULL  |
      +-------+------------+------+-----+---------+-------+
      3 rows in set
      
      obclient> ALTER TABLE test DROP COLUMN c3;
      Query OK, 0 rows affected
      
      obclient> DESCRIBE test;
      +-------+------------+------+-----+---------+-------+
      | FIELD | TYPE       | NULL | KEY | DEFAULT | EXTRA |
      +-------+------------+------+-----+---------+-------+
      | C1    | NUMBER(38) | NO   | PRI | NULL    | NULL  |
      | C2    | CHAR(10)   | YES  | NULL | NULL    | NULL  |
      +-------+------------+------+-----+---------+-------+
      2 rows in set
      

    For more information about the ALTER TABLE statement, see ALTER TABLE.

    Drop a table

    You can execute the DROP TABLE statement to drop a table.

    For example, drop the test table.

    obclient> DROP TABLE test;
    Query OK, 0 rows affected
    

    For more information about the DROP TABLE statement, see DROP TABLE.

    Index operations

    An index is a database structure created for a table to sort data in one or more columns of the table in a specific order. It improves the query speed and reduces the performance overhead of database systems.

    Create indexes

    You can execute the CREATE INDEX statement to create a table index.

    For example, create an index on the test table.

    obclient> DESCRIBE test;
    +-------+------------+------+-----+---------+-------+
    | FIELD | TYPE       | NULL | KEY | DEFAULT | EXTRA |
    +-------+------------+------+-----+---------+-------+
    | C1    | NUMBER(38) | NO   | PRI | NULL    | NULL  |
    | C2    | CHAR(10)   | YES  | NULL | NULL    | NULL  |
    +-------+------------+------+-----+---------+-------+
    2 rows in set
    
    obclient> CREATE INDEX test_index ON test (c1, c2);
    Query OK, 0 rows affected
    

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

    Query indexes

    • Query all indexes on a table by using the ALL_INDEXES view.

      obclient> SELECT OWNER,INDEX_NAME,INDEX_TYPE,TABLE_OWNER,TABLE_NAME FROM ALL_INDEXES WHERE table_name='TEST'\G
      *************************** 1. row ***************************
                        OWNER: SYS
                  INDEX_NAME: TEST_OBPK_1664353339491130
                  INDEX_TYPE: NORMAL
                  TABLE_OWNER: SYS
                  TABLE_NAME: TEST
      *************************** 2. row ***************************
                        OWNER: SYS
                  INDEX_NAME: TEST_INDEX
                  INDEX_TYPE: NORMAL
                  TABLE_OWNER: SYS
                  TABLE_NAME: TEST
      2 rows in set
      
    • Use the USER_IND_COLUMNS statement to view details about the indexes of a table.

      obclient> SELECT * FROM USER_IND_COLUMNS WHERE table_name='TEST'\G
      *************************** 1. row ***************************
              INDEX_NAME: TEST_OBPK_1664353339491130
              TABLE_NAME: TEST
            COLUMN_NAME: C1
        COLUMN_POSITION: 1
          COLUMN_LENGTH: 22
            CHAR_LENGTH: 0
                DESCEND: ASC
      COLLATED_COLUMN_ID: NULL
      *************************** 2. row ***************************
              INDEX_NAME: TEST_INDEX
              TABLE_NAME: TEST
            COLUMN_NAME: C1
        COLUMN_POSITION: 1
          COLUMN_LENGTH: 22
            CHAR_LENGTH: 0
                DESCEND: ASC
      COLLATED_COLUMN_ID: NULL
      *************************** 3. row ***************************
              INDEX_NAME: TEST_INDEX
              TABLE_NAME: TEST
            COLUMN_NAME: C2
        COLUMN_POSITION: 2
          COLUMN_LENGTH: 10
            CHAR_LENGTH: 10
                DESCEND: ASC
      COLLATED_COLUMN_ID: NULL
      3 rows in set
      

    Drop an index

    You can execute the DROP INDEX statement to drop a table index.

    For example, drop the index named test_index.

    obclient> DROP INDEX test_index;
    Query OK, 0 rows affected
    

    For more information about the DROP INDEX statement, see DROP INDEX.

    Insert data

    You can execute the INSERT statement to add one or more records to a table.

    Here are some examples:

    • Use the CREATE TABLE statement to create a table named t1 and insert a row into the t1 table.

      obclient> CREATE TABLE t1(c1 INT PRIMARY KEY, c2 INT);
      Query OK, 0 rows affected
      
      obclient> SELECT * FROM t1;
      Empty set
      
      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 data into the result set of a subquery.

      obclient> INSERT INTO (SELECT * FROM t1) VALUES(2,2);
      Query OK, 1 row affected
      
      obclient> SELECT * FROM t1;
      +----+------+
      | C1 | C2   |
      +----+------+
      |  1 |    1 |
      |  2 |    2 |
      +----+------+
      2 rows in set
      
    • Insert data by using the RETURNING clause.

      obclient> INSERT INTO t1 VALUES(3,3) RETURNING c1;
      +----+
      | C1 |
      +----+
      |  3 |
      +----+
      1 row in set
      
      obclient> SELECT * FROM t1;
      +----+------+
      | C1 | C2   |
      +----+------+
      |  1 |    1 |
      |  2 |    2 |
      |  3 |    3 |
      +----+------+
      3 rows in set
      

    For more information about the INSERT statement, see INSERT.

    Delete data

    You can execute the DELETE statement to delete data.

    For example, delete the row where c1 = 2 from the t1 table.

    obclient> DELETE FROM t1 WHERE c1 = 2;
    Query OK, 1 row affected
    
    obclient> SELECT * FROM t1;
    +----+------+
    | C1 | C2   |
    +----+------+
    |  1 |    1 |
    |  3 |    3 |
    +----+------+
    2 rows in set
    

    For more information about the DELETE statement, see DELETE.

    Update data

    You can execute the UPDATE statement to modify the field values in a table.

    Here are some examples:

    • For the row where t1.c1 = 1 in table t1, set its value in column c2 to 100.

      obclient> UPDATE t1 SET t1.c2 = 100 WHERE t1.c1 = 1;
      Query OK, 1 row affected
      Rows matched: 1  Changed: 1  Warnings: 0
      
      obclient> SELECT * FROM t1;
      +----+------+
      | C1 | C2   |
      +----+------+
      |  1 |  100 |
      |  3 |    3 |
      +----+------+
      2 rows in set
      
    • For the row where v.c1 = 3 in the result set of a subquery, change the value in the c2 column to 300.

      obclient> UPDATE (SELECT * FROM t1) v SET v.c2 = 300 WHERE v.c1 = 3;
      Query OK, 1 row affected
      Rows matched: 1  Changed: 1  Warnings: 0
      
      obclient> SELECT * FROM t1;
      +----+------+
      | C1 | C2   |
      +----+------+
      |  1 |  100 |
      |  3 |  300 |
      +----+------+
      2 rows in set
      

    For more information about the UPDATE statement, see UPDATE.

    Query data

    You can execute the SELECT statement to query data from a table.

    Here are some examples:

    • Use the CREATE TABLE statement to create a table named t2 and query the data in the name field from the t2 table.

      obclient> CREATE TABLE t2 (id INT, name VARCHAR(50), num INT);
      Query OK, 0 rows affected
      
      obclient> INSERT INTO t2 VALUES(1,'a',100),(2,'b',200),(3,'a',50);
      Query OK, 3 rows affected
      Records: 3  Duplicates: 0  Warnings: 0
      
      obclient> SELECT * FROM t2;
      +------+------+------+
      | ID   | NAME | NUM  |
      +------+------+------+
      |    1 | a    |  100 |
      |    2 | b    |  200 |
      |    3 | a    |   50 |
      +------+------+------+
      3 rows in set
      
      obclient> SELECT name FROM t2;
      +------+
      | NAME |
      +------+
      | a    |
      | b    |
      | a    |
      +------+
      3 rows in set
      
    • Deduplicate the query results of the name field.

      obclient> SELECT DISTINCT name FROM t2;
      +------+
      | NAME |
      +------+
      | a    |
      | b    |
      +------+
      2 rows in set
      
    • Return the values of the id, name, and num columns based on the filter condition name = 'a' from table t2.

      obclient> SELECT id, name, num FROM t2 WHERE name = 'a';
      +------+------+------+
      | ID   | NAME | NUM  |
      +------+------+------+
      |    1 | a    |  100 |
      |    3 | a    |   50 |
      +------+------+------+
      2 rows in set
      

    For more information about the SELECT statement, see SELECT.

    Commit a transaction

    You can execute the COMMIT statement to commit a transaction.

    Before you commit the transaction, your modifications are not persisted and take effect only for the current session. You can use the ROLLBACK statement to revoke the modifications.

    After you commit the transaction, your modifications take effect for all database sessions. After your modifications are persisted, you cannot roll them back with a ROLLBACK statement.

    For example, you can execute the CREATE TABLE statement to create a table named t_insert and the COMMIT statement to commit a transaction.

    obclient> CREATE TABLE t_insert(
         id number NOT NULL PRIMARY KEY, 
         name varchar(10) NOT NULL, 
         value number NOT NULL, 
         gmt_create date NOT NULL DEFAULT sysdate
     );
    Query OK, 0 rows affected
    
    obclient> INSERT INTO t_insert(id, name, value, gmt_create) VALUES(1,'CN',10001, sysdate),(2,'US',10002, sysdate),(3,'EN',10003, sysdate);
    Query OK, 3 rows affected
    Records: 3  Duplicates: 0  Warnings: 0
    
    obclient> SELECT * FROM t_insert;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 22-AUG-22  |
    |  2 | US   | 10002 | 22-AUG-22  |
    |  3 | EN   | 10003 | 22-AUG-22  |
    +----+------+-------+------------+
    3 rows in set
    
    obclient> INSERT INTO t_insert(id, name, value) VALUES(4,'JP',10004);
    Query OK, 1 row affected
    
    obclient> COMMIT;
    Query OK, 0 rows affected
    
    obclient> exit;
    Bye
    
    obclient> obclient -h127.0.0.1 -us**@oracle -P2881 -p******
    
    obclient> SELECT * FROM t_insert;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 22-AUG-22  |
    |  2 | US   | 10002 | 22-AUG-22  |
    |  3 | EN   | 10003 | 22-AUG-22  |
    |  4 | JP   | 10004 | 22-AUG-22  |
    +----+------+-------+------------+
    4 rows in set
    

    For more information about transaction control statements, see Overview of transaction management.

    Roll back a transaction

    You can execute the ROLLBACK statement to roll back a transaction.

    In a database, a transaction rollback is used to undo any modifications made during a transaction. You can undo all modifications made within an uncommitted transaction or roll back a transaction to a specific savepoint. To roll back to a specific savepoint, both the ROLLBACK and TO SAVEPOINT statements must be used.

    • If you undo all modifications made within an uncommitted transaction, note that:

      • The transaction will end.
      • All modifications made from the start of the transaction will be discarded.
      • All savepoints will be cleared.
      • All locks held by the transaction will be released.
    • If you roll back a transaction to a specific savepoint, note that:

      • The transaction will not end.
      • Modifications made before the savepoint will be retained but those made after it will be discarded.
      • All savepoints after the specific savepoint will be cleared.
      • All locks held by the transaction after the specific savepoint will be released.

    For example, you can execute the following statements to undo all the modifications of a transaction.

    obclient> SELECT * FROM t_insert;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 29-SEP-22  |
    |  2 | US   | 10002 | 29-SEP-22  |
    |  3 | EN   | 10003 | 29-SEP-22  |
    |  4 | JP   | 10004 | 29-SEP-22  |
    +----+------+-------+------------+
    4 rows in set
    
    obclient> INSERT INTO t_insert(id, name, value) VALUES(5,'FR',10005),(6,'RU',10006);
    Query OK, 3 rows affected
    Records: 3  Duplicates: 0  Warnings: 0
    
    obclient> SELECT * FROM t_insert;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 22-AUG-22  |
    |  2 | US   | 10002 | 22-AUG-22  |
    |  3 | EN   | 10003 | 22-AUG-22  |
    |  4 | JP   | 10004 | 22-AUG-22  |
    |  5 | FR   | 10005 | 22-AUG-22  |
    |  6 | RU   | 10006 | 22-AUG-22  |
    +----+------+-------+------------+
    6 rows in set
    
    obclient> ROLLBACK;
    Query OK, 0 rows affected
    
    obclient> SELECT * FROM t_insert;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 29-SEP-22  |
    |  2 | US   | 10002 | 29-SEP-22  |
    |  3 | EN   | 10003 | 29-SEP-22  |
    |  4 | JP   | 10004 | 29-SEP-22  |
    +----+------+-------+------------+
    3 rows in set
    

    For more information about transaction control statements, see Overview of transaction management.

    Previous topic

    Basic SQL operations (MySQL mode)
    Last

    Next topic

    Build a Java application
    Next
    What is on this page
    Table operations
    Create a table
    Modify a table
    Drop a table
    Index operations
    Create indexes
    Query indexes
    Drop an index
    Insert data
    Delete data
    Update data
    Query data
    Commit a transaction
    Roll back a transaction