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

    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.2.5
    iconOceanBase Database
    SQL - V 4.2.5
    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

    UPDATE

    Last Updated:2026-04-09 09:38:52  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Example 1
    Example 2

    folded

    share

    Purpose

    This statement is used to modify the existing field values in a table.

    Syntax

    UPDATE [hint_options] dml_table_clause
        SET update_asgn_list
        [ WHERE where_condition]
        [{ RETURNING | RETURN } returning_exprs [into_clause]]
    
    dml_table_clause:
        dml_table_name opt_table_alias
    
    update_asgn_list:
        column_name = expr [, expr...]
    
    where_condition:
        expression
    
    returning_exprs:
        projection_col_name [,projection_col_name ...]
    
    into_clause:
        { INTO into_var_list | BULK COLLECT INTO into_var_list}
    
    into_var_list:
        { USER_VARIABLE | ref_name } [,{ USER_VARIABLE | ref_name } ...]
    

    Parameters

    Parameter Description
    hint_options Specifies the hint options.
    dml_table_clause Specifies the name of the table, view, or special subquery that returns the columns to be updated.
    Note If you specify view, the database updates the base table of the view. However, you cannot update multiple base tables through a single view.
    where_condition Specifies the filter conditions.
    update_asgn_list Specifies the update list.
    returning_exprs Specifies the projected columns after the data is modified.
    into_clause Inserts the projected columns after the data is modified into the specified list.
    into_var_list Inserts the specified projected columns into the specified variable list.
    ref_name The variable name.

    Notice

    A special subquery refers to a subquery similar to that corresponding to an updatable view. Such subqueries should not contain complex operators (such as GROUP BY, DISTINCT, and WINDOW FUNCTION).

    Example 1

    Create the sample table tbl1 and insert test data.

    obclient> CREATE TABLE tbl1(col1 INT PRIMARY KEY,col2 INT);
    Query OK, 0 rows affected
    
    obclient> INSERT INTO tbl1 VALUES(1,1),(2,2),(3,3),(4,4),(5,5);
    Query OK, 5 rows affected
    Records: 5  Duplicates: 0  Warnings: 0
    
    obclient> SELECT * FROM tbl1;
    +------+------+
    | COL1 | COL2 |
    +------+------+
    |    1 |    1 |
    |    2 |    2 |
    |    3 |    3 |
    |    4 |    4 |
    |    5 |    5 |
    +------+------+
    5 rows in set
    
    • Single-table update: Modify the col2 value of the row in the tbl1 table where tbl1.col1=1 to 100.

      obclient> UPDATE tbl1 SET tbl1.col2 = 100  WHERE tbl1.col1 = 1;
      Query OK, 1 row affected
      Rows matched: 1  Changed: 1  Warnings: 0
      
      obclient> SELECT * FROM tbl1;
      +------+------+
      | COL1 | COL2 |
      +------+------+
      |    1 |  100 |
      |    2 |    2 |
      |    3 |    3 |
      |    4 |    4 |
      |    5 |    5 |
      +------+------+
      5 rows in set
      
    • Single-table update: Directly operate on the subquery and modify the col2 value of the row in the subquery where v.col1=1 to 10.

      obclient> UPDATE (SELECT * FROM tbl1) v SET v.col2 = 10 WHERE v.col1 = 1;
      Query OK, 1 row affected
      Rows matched: 1  Changed: 1  Warnings: 0
      
      obclient> SELECT * FROM tbl1;
      +------+------+
      | COL1 | COL2 |
      +------+------+
      |    1 |   10 |
      |    2 |    2 |
      |    3 |    3 |
      |    4 |    4 |
      |    5 |    5 |
      +------+------+
      5 rows in set
      
    • Single-table update: Modify the col2 value of the rows in the tbl1 table where tbl1.col1<3 to 100.

      obclient> UPDATE tbl1 SET tbl1.col2 = 100 WHERE tbl1.col1 < 3;
      Query OK, 2 rows affected
      Rows matched: 2  Changed: 2  Warnings: 0
      
      obclient> SELECT * FROM tbl1;
      +------+------+
      | COL1 | COL2 |
      +------+------+
      |    1 |  100 |
      |    2 |  100 |
      |    3 |    3 |
      |    4 |    4 |
      |    5 |    5 |
      +------+------+
      5 rows in set
      
    • Single-table update: Use the RETURNING clause to return the modified data.

      obclient> UPDATE tbl1 SET tbl1.col2 = 1000 WHERE tbl1.col1 = 1 RETURNING col2;
      +------+
      | COL2 |
      +------+
      | 1000 |
      +------+
      1 row in set
      
      obclient> SELECT * FROM tbl1;
      +------+------+
      | COL1 | COL2 |
      +------+------+
      |    1 | 1000 |
      |    2 |    2 |
      |    3 |    3 |
      |    4 |    4 |
      |    5 |    5 |
      +------+------+
      5 rows in set
      

    Example 2

    1. Create the sample tables.

      CREATE TABLE employees1 (
          id NUMBER,
          name VARCHAR2(20),
          salary NUMBER
      );
      
      CREATE TABLE employees2 (
          id NUMBER,
          name VARCHAR2(20),
          salary NUMBER
      );
      
    2. Insert test data.

      INSERT INTO employees1 VALUES (1, 'Jack', 5000);
      INSERT INTO employees2 VALUES (1, 'Tom', 3000);
      
    3. Perform a table update operation using variables.

       -- Declare variables
       DECLARE
           var_emp employees1%ROWTYPE;
       BEGIN
           -- Retrieve data from employees1 into the variable
           SELECT * INTO var_emp
           FROM employees1
           WHERE id = 1;
      
           -- Use the variable to update the employees2 table
           UPDATE employees2
           SET (name) = (var_emp.name);
      
           COMMIT;
       END;
       /
      

    Previous topic

    WITH CLAUSE
    Last

    Next topic

    ANALYZE
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Example 1
    Example 2