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

    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.1
    iconOceanBase Database
    SQL - V 4.3.1
    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

    INSERTCHILDXML

    Last Updated:2026-04-15 08:25:15  Updated
    share
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples

    folded

    share

    Purpose

    INSERTCHILDXML() inserts the specified XML fragment into nodes indicated by an XPath expression in the target XML document.

    Syntax

    INSERTCHILDXML( XMLType_instance, XPath_string, child_expr, value_expr [, namespace_string ])
    

    Parameters

    Parameter Description
    XMLType_instance The XMLType instance that represents the target XML document.
    XPath_string The XPath expression that indicates one or more target nodes into which one or more child nodes are to be inserted. You can use an absolute path (starting with a slash) or a relative path (with the initial slash omitted). If the initial slash is omitted, the context of the relative path is the root node by default.
    child_expr The one or more element or attribute nodes to be inserted.
    value_expr The XMLType fragment that specifies one or more nodes to be inserted. It must resolve to a string or XMLType data.
    namespace_string The namespace information for XPath_string. This parameter is optional.

    Note

    If target parent nodes have other namespaces but child nodes to be inserted do not, all the child nodes need to be traversed and configured with an empty namespace.

    Return type

    The return type is XMLType.

    Examples

    • Call INSERTCHILDXML() to insert a child node into the target XML document, which is the <bookstore> node and its child nodes. The XPath expression is /bookstore, which indicates that the child node is to be inserted into the <bookstore> node. The name of the target child node to be inserted is price. The content of the child node to be inserted is an XMLType instance representing <price>99.9</price>. The query result is renamed as result by using the AS keyword. Finally, the result is retrieved from the dual table.

      SELECT INSERTCHILDXML(
              XMLtype('<bookstore>
                          <book att="old"></book>
                          <author>carrot</author>
                        </bookstore>'), 
              '/bookstore', 
              'price', 
              XMLtype('<price>99.9</price>')
            ) AS result
      FROM dual;
      

      The return result is as follows:

      +-----------------------------------------------------------------------------------------------+
      | RESULT                                                                                        |
      +-----------------------------------------------------------------------------------------------+
      | <bookstore>
        <book att="old"/>
        <author>carrot</author>
        <price>99.9</price>
      </bookstore>
      |
      +-----------------------------------------------------------------------------------------------+
      1 row in set
      
    • Insert a node.

      SELECT 
        INSERTCHILDXML(
          xmltype(
            '<bookstore>
              <book att="old"></book>
              <author>carrot</author>
            </bookstore>'
          ), 
          '/bookstore/book', 
          'a', 
          xmltype('<a><b/></a>')
        )
      FROM dual;
      

      The return result is as follows:

      +----------------------------------------------------------------------------------------------------------------------------------------------+
      | INSERTCHILDXML(XMLTYPE('<BOOKSTORE><BOOKATT="OLD"></BOOK><AUTHOR>CARROT</AUTHOR></BOOKSTORE>'),'/BOOKSTORE/BOOK','A',XMLTYPE('<A><B/></A>')) |
      +----------------------------------------------------------------------------------------------------------------------------------------------+
      | <bookstore>
        <book att="old">
          <a>
            <b/>
          </a>
        </book>
        <author>carrot</author>
      </bookstore>
                                      |
      +----------------------------------------------------------------------------------------------------------------------------------------------+
      1 row in set
      
    • If the XPath matches multiple nodes, the specified child node is inserted into each of the nodes.

      SELECT 
        INSERTCHILDXML(
          xmltype(
            '<bookstore>
              <book att="old"></book>
              <book></book>
              <author>carrot</author>
            </bookstore>'
          ), 
          '/bookstore/book', 
          'price', 
          xmltype('<price>99.9</price>')
        ) 
      FROM dual;
      

      The return result is as follows:

      +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | INSERTCHILDXML(XMLTYPE('<BOOKSTORE><BOOKATT="OLD"></BOOK><BOOK></BOOK><AUTHOR>CARROT</AUTHOR></BOOKSTORE>'),'/BOOKSTORE/BOOK','PRICE',XMLTYPE('<PRICE>99.9</PRICE>')) |
      +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | <bookstore>
        <book att="old">
          <price>99.9</price>
        </book>
        <book>
          <price>99.9</price>
        </book>
        <author>carrot</author>
      </bookstore>
                        |
      +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      1 row in set
      
    • Insert an attribute.

      SELECT 
        INSERTCHILDXML(
          xmltype(
            '<bookstore>
              <book att="old"></book>
              <author>carrot</author>
            </bookstore>'
          ), 
          '/bookstore/book', 
          '@att2', 
          'abc'
        ) 
      FROM dual;
      

      The return result is as follows:

      +---------------------------------------------------------------------------------------------------------------------------------+
      | INSERTCHILDXML(XMLTYPE('<BOOKSTORE><BOOKATT="OLD"></BOOK><AUTHOR>CARROT</AUTHOR></BOOKSTORE>'),'/BOOKSTORE/BOOK','@ATT2','ABC') |
      +---------------------------------------------------------------------------------------------------------------------------------+
      | <bookstore>
        <book att="old" att2="abc"/>
        <author>carrot</author>
      </bookstore>
                                                    |
      +---------------------------------------------------------------------------------------------------------------------------------+
      1 row in set
      

    Previous topic

    UPDATEXML
    Last

    Next topic

    DELETEXML
    Next
    What is on this page
    Purpose
    Syntax
    Parameters
    Return type
    Examples