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

    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.6.0
    iconOceanBase Database
    SQL - V 4.6.0
    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

    TRANSACTION

    Last Updated:2026-05-07 11:26:25  Updated
    Share
    What is on this page
    Syntax
    Parameters
    Examples

    folded

    Share

    TRANSACTION related statements are used to manage database transactions.

    A database transaction is a series of operations that are executed as a single logical unit. Transaction processing can be used to maintain database integrity and ensure that all SQL operations in a batch are either executed or not executed.

    Explicit transactions are user-defined or user-specified transactions. An explicit transaction starts with the BEGIN or BEGIN WORK statement (which is an alias for START TRANSACTION) and ends with the COMMIT or 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. Once a transaction is started, subsequent SQL data manipulation statements (such as INSERT, UPDATE, and DELETE) will only take effect until explicitly committed. READ ONLY indicates that the transaction is started in read-only mode, and no modification operations can be executed within the transaction. READ WRITE indicates that the transaction is started in read-write mode, which is the default mode.
    BEGIN [WORK] BEGIN and BEGIN WORK are aliases for START TRANSACTION.
    COMMIT [WORK] Commits the current transaction, making all modifications in the transaction permanent.
    ROLLBACK [WORK] Rolls back the current transaction, undoing all modifications in the transaction.
    SET TRANSACTION {READ ONLY | READ WRITE} Sets the current transaction to READ ONLY or READ WRITE mode.

    Examples

    Use START TRANSACTION to start and commit a transaction.

    obclient> CREATE TABLE order_table(id INT PRIMARY KEY, order_name VARCHAR(50), amount DECIMAL(10,2));
    
    obclient> START TRANSACTION;
    
    obclient> INSERT INTO order_table VALUES (1, 'Order001', 100.50);
    
    obclient> UPDATE order_table SET amount = 150.00 WHERE id = 1;
    
    obclient> COMMIT;
    

    Use BEGIN to start and roll back a transaction.

    obclient> BEGIN;
    
    obclient> INSERT INTO order_table VALUES (2, 'Order002', 200.00);
    
    obclient> UPDATE order_table SET amount = 250.00 WHERE id = 2;
    
    obclient> ROLLBACK;
    

    After rolling back, query the table data to confirm that the modifications have been undone.

    obclient> SELECT * FROM order_table;
    

    The query result is as follows:

    +----+-----------+--------+
    | id | order_name| amount |
    +----+-----------+--------+
    |  1 | Order001  | 150.00 |
    +----+-----------+--------+
    1 row in set
    

    Use SET TRANSACTION to set the transaction to read-only mode.

    obclient> SET TRANSACTION READ ONLY;
    
    obclient> START TRANSACTION;
    
    obclient> SELECT * FROM order_table;
    

    Notice

    • Before COMMIT is executed, you can check whether the operations in the current transaction have taken effect. For example, you can execute the SQL statement SELECT * FROM order_table; before COMMIT is executed.
    • Within the current transaction session, the latest results can be accessed, but outside the transaction session, the results are not effective. Before COMMIT is executed, the operations performed are only visible within the current transaction session.
    • To roll back the transaction, use ROLLBACK instead of COMMIT.

    Previous topic

    CANCEL JOB
    Last

    Next topic

    TRUNCATE TABLE
    Next
    What is on this page
    Syntax
    Parameters
    Examples