OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

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

A unified distributed database ready for your transactional, analytical, and AI workloads.

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 & Certification
    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
    SQL
    KV
    • 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

    TRANSACTION

    Last Updated:2025-11-27 02:38:06  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples

    folded

    share

    Purpose

    You can use this statement to start a transaction.

    A database transaction is a series of operations performed as a logical unit of work. A transaction can be used to maintain the integrity of the database by ensuring that SQL operations in a batch are either all executed or none of them are executed.

    Explicit transactions are user-defined or user-specified transactions. You can explicitly start a transaction by using the BEGIN or BEGIN WORK statement (which are aliases of START TRANSACTION) and explicitly end the transaction by using the COMMIT or ROLLBACK statement.

    Note

    • Before you commit a transaction, you can execute a SELECT statement to check whether the operations in the transaction have taken effect.
    • Before a transaction is committed, the operations in this transaction are invisible to sessions other than the session of the current transaction. In other words, before a transaction is committed, only the session of the current transaction can read the latest results.
    • To roll back the transaction, directly execute the ROLLBACK statement.

    Syntax

    transaction_stmt:
          START TRANSACTION [READ ONLY | READ WRITE];
        | BEGIN [WORK];
        | COMMIT [WORK];
        | ROLLBACK [WORK];
        | SET TRANSACTION {READ ONLY | READ WRITE};
    

    Parameters

    Parameter Description
    START TRANSACTION [READ ONLY | READ WRITE] Starts a transaction. After a transaction is started, the subsequent SQL data operation statements (such as INSERT, UPDATE, and DELETE) do not take effect until it is explicitly committed.
    • The READ ONLY clause specifies to start the transaction in read-only mode. In this mode, modifications to the transaction are not allowed.
    • The READ WRITE clause specifies to start the transaction in read and write mode, which is the default mode.
    BEGIN BEGIN and BEGIN WORK are used as aliases of START TRANSACTION.
    COMMIT Commits the current transaction.
    ROLLBACK Rolls back the current transaction.
    SET TRANSACTION {READ ONLY | READ WRITE} Sets the current transaction to the READ ONLY or READ WRITE mode.

    Examples

    Create a table named tbl1.

    obclient> CREATE TABLE tbl1 (id INT,name VARCHAR(10),num INT);
    Query OK, 0 rows affected
    
    obclient> INSERT INTO tbl1 VALUES (1, 'a',100),(2, 'b',200),(3, 'a',50);
    Query OK, 3 rows affected
    Records: 3  Duplicates: 0  Warnings: 0
    
    obclient> SELECT * FROM tbl1;
    +------+------+------+
    | ID   | NAME | NUM  |
    +------+------+------+
    |    1 | a    |  100 |
    |    2 | b    |  200 |
    |    3 | a    |   50 |
    +------+------+------+
    3 rows in set
    
    • Start a transaction, change the name to c for the row where id is 3, and insert one row. Commit the transaction and query the information about the tbl1 table.

      obclient> START TRANSACTION;
      Query OK, 0 rows affected
      
      obclient> UPDATE tbl1 SET name = 'c' WHERE id = 3;
      Query OK, 1 row affected
      Rows matched: 1  Changed: 1  Warnings: 0
      
      obclient> INSERT INTO tbl1 VALUES (4, 'a', 30);
      Query OK, 1 row affected
      
      obclient> COMMIT;
      Query OK, 0 rows affected
      
      obclient> SELECT * FROM tbl1;
      +------+------+------+
      | ID   | NAME | NUM  |
      +------+------+------+
      |    1 | a    |  100 |
      |    2 | b    |  200 |
      |    3 | c    |   50 |
      |    4 | a    |   30 |
      +------+------+------+
      4 rows in set
      
    • Start a transaction, change the name to c for the row where id is 3, insert one row, and query the information about the tbl1 table. Then roll back the transaction and query the information about the tbl1 table again.

      obclient> BEGIN;
      Query OK, 0 rows affected
      
      obclient> UPDATE tbl1 SET name = 'c' WHERE id = 3;
      Query OK, 1 row affected
      Rows matched: 1  Changed: 1  Warnings: 0
      
      obclient> INSERT INTO tbl1 VALUES (4, 'd', 300);
      Query OK, 1 row affected
      
      obclient> SELECT * FROM tbl1;
      +------+------+------+
      | ID   | NAME | NUM  |
      +------+------+------+
      |    1 | a    |  100 |
      |    2 | b    |  200 |
      |    3 | c    |   50 |
      |    4 | d    |  300 |
      +------+------+------+
      4 rows in set
      
      obclient> ROLLBACK ;
      Query OK, 0 rows affected
      
      obclient> SELECT * FROM tbl1;
      +------+------+------+
      | ID   | NAME | NUM  |
      +------+------+------+
      |    1 | a    |  100 |
      |    2 | b    |  200 |
      |    3 | a    |   50 |
      +------+------+------+
      3 rows in set
      

    Previous topic

    SHRINK
    Last

    Next topic

    Overview
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Examples