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

    JSON_MERGEPATCH

    Last Updated:2026-05-07 11:26:26  Updated
    share
    What is on this page
    Purpose
    Syntax
    Syntax
    Examples

    folded

    share

    Purpose

    The JSON_MERGEPATCH() function updates a specific part of the target_json data. It follows RFC 7396 to merge two or more JSON documents and returns the merged result, omitting members that have duplicate keys. If at least one document passed as an argument to this function is invalid, an error is raised.

    The JSON_MERGEPATCH() function performs the following merge operation:

    • If the first argument is not an object, the result of merging with the second argument is the same as merging the empty object with the second argument.
    • If the second argument is not an object, then the result of the merge is the second argument.
    • If both arguments are objects, the merged result is an object with the following members:
      • The members of the first object do not have corresponding members in the second object with the same keys.
      • The second object has members that are not present in the first object and are not JSON null values.
    • The keys of all the members exist in the first and second object, and their values in the second object are not JSON Null values.
    • The values for these members are the result of recursively merging values from the first object into the second.

    Syntax

    JSON_MERGEPATCH (
                     target_expr,
                     patch_expr
                     [RETURNING  CLOB|BLOB|JSON|VARCHAR2|VARCHAR2[size],]
                     [PRETTY]
                     [ASCII]
                     [TRUNCATE]
                     [ERROR|NULL ON ERROR]);
    

    Syntax

    The syntax for the JSON_MERGEPATCH() function is described as follows:

    • target_expr: The target JSON object.
    • patch_expr: A JSON object containing the patch expressions.
    • RETURNING CLOB|BLOB|JSON|VARCHAR2|VARCHAR2[size] : This clause specifies the return type. VARCHAR2[size] specifies the maximum return value length.
    • PRETTY: specifies whether to use pretty-print output for the returned character data.
    • ASCII: Use the standard ASCII Unicode escape sequence to automatically escape any non-ASCII Unicode character in the returned string.
    • TRUNCATE: A clause that specifies that the text returned should be truncated according to the return type.
    • ERROR clause:
      • NULL ON ERROR : Returns NULL when an error occurs. This is the default setting.
      • ERROR ON ERROR : The error code is returned.

    Examples

    # Use the default parameters.
    obclient> SELECT json_mergepatch('{"a":"b"}', '{"b":"c"}') FROM DUAL;
    +------------------------------------------+
    | JSON_MERGEPATCH('{"A":"B"}','{"B":"C"}') |
    +------------------------------------------+
    | {"a": "b", "b": "c"}                     |
    +------------------------------------------+
    1 row in set
    
    # When the patch is null, it is equivalent to deleting.
    obclient> SELECT json_mergepatch('{"a":"b"}', '{"a":null}') FROM DUAL;
    +-------------------------------------------+
    | JSON_MERGEPATCH('{"A":"B"}','{"A":NULL}') |
    +-------------------------------------------+
    | {}                                        |
    +-------------------------------------------+
    1 row in set
    
    # When the keys are the same, the value is updated.
    obclient> SELECT json_mergepatch('{"a":["b"]}', '{"a":"c"}') FROM DUAL;
    +--------------------------------------------+
    | JSON_MERGEPATCH('{"A":["B"]}','{"A":"C"}') |
    +--------------------------------------------+
    | {"a": "c"}                                 |
    +--------------------------------------------+
    1 row in set
    
    # Use the RETURNING and PRETTY clauses.
    obclient> SELECT json_mergepatch('{"a":"b", "b":"c"}', '{"a":null}' RETURNING CLOB PRETTY ) FROM DUAL;
    +----------------------------------------------------------------------+
    | JSON_MERGEPATCH('{"A":"B","B":"C"}','{"A":NULL}'RETURNINGCLOBPRETTY) |
    +----------------------------------------------------------------------+
    | {
      "b": "c"
    }                                                       |
    +----------------------------------------------------------------------+
    1 row in set
    
    # Use the TRUNCATE clause.
    obclient> SELECT json_mergepatch(
          '{"a":"b"}',
          '{"a":"cccccccccccccccccccccccccccccbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccc"}'
              RETURNING varchar2(32) PRETTY TRUNCATE) FROM DUAL;
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | JSON_MERGEPATCH('{"A":"B"}','{"A":"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"}'RETURNINGVARCHAR2(32)PRETTYTRUNCATE) |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | {
      "a": "cccccccccccccccccccccc                                                                                                                                                                                                        |
    +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set
    
    # Use the ERROR clause.
    obclient> SELECT json_mergepatch('{', '[1,2,3]' ERROR ON ERROR) FROM DUAL;
    OBE-40441: JSON syntax error
    
    # By default, returns NULL when an error occurs.
    obclient> SELECT json_mergepatch('{', '[1,2,3]') FROM DUAL;
    +--------------------------------+
    | JSON_MERGEPATCH('{','[1,2,3]') |
    +--------------------------------+
    | NULL                           |
    +--------------------------------+
    1 row in set
    
    # Specify the ERROR clause
    obclient> SELECT json_mergepatch('{', '[1,2,3]' NULL ON ERROR) FROM DUAL;
    +-------------------------------------------+
    | JSON_MERGEPATCH('{','[1,2,3]'NULLONERROR) |
    +-------------------------------------------+
    | NULL                                      |
    +-------------------------------------------+
    1 row in set
    
    

    Previous topic

    JSON_EQUAL
    Last

    Next topic

    Overview of XML functions
    Next
    What is on this page
    Purpose
    Syntax
    Syntax
    Examples