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

    Commit a transaction

    Last Updated:2026-04-15 08:27:13  Updated
    share
    What is on this page
    Commit a transaction
    Commit a transaction explicitly
    Commit a transaction implicitly
    References

    folded

    share

    Committing a transaction will persist all changes made in the transaction, delete the savepoints, and release all locks held by the transaction.

    Commit a transaction

    In OceanBase Database, you can commit transactions explicitly or implicitly. To explicitly commit a transaction, use the COMMIT statement or the commit button on a GUI-based client. To implicitly commit a transaction, you do not need to proactively commit it. When autocommit is set to 1, after each statement is executed, OceanBase Database will automatically commit the transaction where this statement is executed. A statement is a transaction.

    Note

    OceanBase Database issues an implicit COMMIT statement before and after a DDL statement, which also commits a transaction.

    • If you use the BEGIN statement to start a new transaction, you must use the COMMIT statement to commit the transaction after you execute a DML statement.

      • Before you commit a transaction, your changes are visible only to the current session and not for other database sessions. These changes are not persisted and therefore not the final result. You can use the ROLLBACK statement to roll back the changes.

      • After you commit the transaction, your changes are visible to all database sessions. After your changes are persisted, you cannot roll them back with a ROLLBACK statement.

      Note

      If the repeatable read isolation level is set for the transaction, sessions where the transaction is started cannot query newly committed data. For more information about transaction isolation levels, see Transaction isolation levels.

    • If transactions are started implicitly, namely, autocommit is set to 1 to enable the autocommit mode, each SQL statement is a transaction. In this case, you do not need to execute the COMMIT statement to commit the SQL statements as one transaction. After the SQL statements are executed, your changes are persisted, and you cannot roll them back with a ROLLBACK statement.

    Commit a transaction explicitly

    Use BEGIN to start a transaction, use INSERT to insert data into the ordr table, and then use COMMIT to commit the transaction.

    obclient [SYS]> SELECT * FROM ordr;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 03-NOV-22  |
    |  2 | US   | 10002 | 03-NOV-22  |
    |  3 | EN   | 10003 | 03-NOV-22  |
    +----+------+-------+------------+
    3 rows in set
    
    obclient [SYS]> BEGIN;
    Query OK, 0 rows affected
    
    obclient [SYS]> INSERT INTO ordr(id,name) VALUES(4,'JP');
    Query OK, 1 row affected
    
    obclient [SYS]> COMMIT;
    Query OK, 0 rows affected
    

    Close and then reestablish the session. You will find that the data is inserted and saved.

    obclient [SYS]> exit;
    
    $obclient -h192.168.0.0 -utpcc@obbmsql#obdemo -P2883 -p******
    Welcome to the OceanBase.  Commands end with ; or \g.
    Your OceanBase connection id is 3221487661
    Server version: OceanBase 4.0.0.0 (r100000252022102910-df01cef074936b9c9f177697500fad1dc304056f) (Built Oct 29 2022 10:27:50)
    
    Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    obclient [SYS]> SELECT * FROM ordr;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 03-NOV-22  |
    |  2 | US   | 10002 | 03-NOV-22  |
    |  3 | EN   | 10003 | 03-NOV-22  |
    |  4 | JP   | NULL  | 03-NOV-22  |
    +----+------+-------+------------+
    4 rows in set
    

    Commit a transaction implicitly

    Set the autocommit variable to 1 to enable the autocommit mode.

    obclient [SYS]> SELECT * FROM ordr;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 03-NOV-22  |
    |  2 | US   | 10002 | 03-NOV-22  |
    |  3 | EN   | 10003 | 03-NOV-22  |
    +----+------+-------+------------+
    4 rows in set
    
    obclient> SET autocommit=1;
    Query OK, 1 row affected
    
    INSERT INTO ordr(id,name) VALUES(4,'JP');
    Query OK, 1 row affected
    

    Close and then reconnect the session. You will find that the data is inserted and saved.

    obclient [SYS]> exit;
    
    $obclient -h192.168.0.0 -utpcc@obbmsql#obdemo -P2883 -p******
    Welcome to the OceanBase.  Commands end with ; or \g.
    Your OceanBase connection id is 3221487664
    Server version: OceanBase 4.0.0.0 (r100000252022102910-df01cef074936b9c9f177697500fad1dc304056f) (Built Oct 29 2022 10:27:50)
    
    Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    obclient [SYS]> SELECT * FROM ordr;
    +----+------+-------+------------+
    | ID | NAME | VALUE | GMT_CREATE |
    +----+------+-------+------------+
    |  1 | CN   | 10001 | 03-NOV-22  |
    |  2 | US   | 10002 | 03-NOV-22  |
    |  3 | EN   | 10003 | 03-NOV-22  |
    |  4 | JP   | NULL  | 03-NOV-22  |
    +----+------+-------+------------+
    4 rows in set
    

    References

    • Start a transaction

    Previous topic

    Roll back a transaction to a savepoint
    Last

    Next topic

    Roll back a transaction
    Next
    What is on this page
    Commit a transaction
    Commit a transaction explicitly
    Commit a transaction implicitly
    References