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 Cloud

    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 Cloud
    iconOceanBase Cloud
    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

      Use the SELECT ... LOCK IN SHARE MODE statement to lock query results

      Last Updated:2026-05-29 03:53:36  Updated
      Share
      What is on this page
      Examples

      folded

      Share

      You can use the SELECT ... LOCK IN SHARE MODE statement to obtain a shared lock when you query data. This prevents other transactions from writing data but allows other transactions to read data. This statement sets a shared lock on the read data rows. Other sessions can read these rows but cannot modify them until the current transaction is committed.

      Notice

      OceanBase Cloud simulates the feature of the LOCK IN SHARE MODE syntax using write locks. This can meet the compatibility requirements of some software while ensuring the correctness of the syntax. Write locks can cause blocking between read operations that use the LOCK IN SHARE MODE syntax. Therefore, we recommend that you do not use this syntax, especially in performance-sensitive scenarios.

      This topic provides specific examples on how to use the SELECT ... LOCK IN SHARE MODE statement to lock query results.

      Examples

      1. In Session 1, start a transaction.

        START TRANSACTION;
        
      2. In Session 1, use the LOCK IN SHARE MODE syntax to query the row where the id value is 1 in the test_tbl1 table and obtain a shared lock.

        SELECT * FROM test_tbl1 WHERE id = 1 LOCK IN SHARE MODE;
        

        The return result is as follows:

        +------+------+
        | id   | name |
        +------+------+
        |    1 | A1   |
        +------+------+
        1 row in set
        
      3. In Session 2, start a transaction.

        START TRANSACTION;
        
      4. In Session 2, query the row where the id value is 1 in the test_tbl1 table.

        SELECT * FROM test_tbl1 WHERE id = 1;
        

        The return result is as follows:

        +------+------+
        | id   | name |
        +------+------+
        |    1 | A1   |
        +------+------+
        1 row in set
        
      5. In Session 2, change the name value to A1A1A1 for the row where the id value is 1 in the test_tbl1 table. This transaction will remain pending until the transaction in Session 1 is rolled back or committed.

        UPDATE test_tbl1 SET name = 'A1A1A1' WHERE id = 1;
        

        The return result is as follows:

        ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
        
      6. In Session 1, commit the transaction.

        COMMIT;
        
      7. In Session 2, execute the UPDATE statement in Step 5 again.

        UPDATE test_tbl1 SET name = 'A1A1A1' WHERE id = 1;
        

        The return result is as follows:

        Query OK, 1 row affected
        Rows matched: 1  Changed: 1  Warnings: 0
        

      Previous topic

      Use the SELECT ... FOR UPDATE statement to lock query results
      Last

      Next topic

      Use a DBLink in queries
      Next
      What is on this page
      Examples