Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Functions of the XMLType Type

Updated on 2024-05-07 GMT+08:00
  • createxml(varchar2[,varchar2,numeric ,numeric])

    Description: Statically creates the XMLType type. The input parameters are of the varchar2 type.

    Parameters: The first parameter is the character string to be converted to XMLType (mandatory column). The second parameter is the optional schema URL used to make the input comply with the specified schema (optional column, which is empty by default and does not take effect currently). The third parameter is the flag indicating whether the instance is valid according to the given XML schema (optional column, which is 0 by default and does not take effect currently). The fourth parameter is the flag indicating whether the instance is well-formed (optional column, which is 0 by default and does not take effect currently).

    Return type: XMLType

    Example:
    1
    2
    3
    4
    5
    gaussdb=# SELECT createxml('<a>123</a>');
     createxml
    --------------
     <a>123</a>
    (1 row)
    
    NOTE:
    • Different from that in database A, in PL/SQL, createxml allows input parameters to be empty strings and returns NULL.
    • For character encoding, only UTF-8, GBK, and LATIN1 to LATIN10 are supported, and the version field can only be set to 1.x.
    • The createxml function can be called using the xmltype.createxml() syntax.
      Example:
      1
      2
      3
      4
      5
      gaussdb=# SELECT xmltype.createxml('<a>123</a>');
       createxml  
      ------------
       <a>123</a>
      (1 row)
      
    • In this chapter, the function whose input parameter is xmltype() can be called in xmltype().func() mode. The XMLType type returned by a function is transferred to the next function as the input parameter. This syntax supports multi-layer nesting. (If the input parameter is defined as XMLType by a user, this syntax is not supported.)
      Example:
      1
      2
      3
      4
      5
      gaussdb=# select xmltype('<a>123<b>456</b></a>').extract('/a/b').getstringval();
       xmltypefunc 
      -------------
       <b>456</b>
      (1 row)
      
      The actual effect of the preceding example is the same as that of the following function nesting:
      1
      2
      3
      4
      5
      gaussdb=# select getstringval(extractxml(xmltype('<a>123<b>456</b></a>'),'/a/b'));
       getstringval 
      --------------
       <b>456</b>
      (1 row)
      
    • In a stored procedure, variables of the XMLType type can call functions in a.func() mode. This syntax supports one-layer nesting.

      Example:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      gaussdb=# declare
                a xmltype;
                b varchar2;
      begin
                a:=xmltype('<a>123<b>456</b></a>');
                b:=a.getstringval();
                RAISE NOTICE 'xmltype_str is : %',b;
      end;
      /
      NOTICE:  xmltype_str is : <a>123<b>456</b></a>
      
  • createxml(clob [,varchar2,numeric ,numeric])

    Description: Statically creates the XMLType type. The input parameters are of the CLOB type.

    Parameters: The first parameter is the CLOB to be converted to XMLType (mandatory column). The second parameter is the optional schema URL used to make the input comply with the specified schema (optional column, which is empty by default and does not take effect currently). The third parameter is the flag indicating whether the instance is valid according to the given XML schema (optional column, which is 0 by default and does not take effect currently). The fourth parameter is the flag indicating whether the instance is well-formed (optional column, which is 0 by default and does not take effect currently).

    Return type: XMLType

    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    gaussdb=# declare
     xmltype_clob clob;
     xmltype_obj xmltype;
     xmltype_str varchar2(1000);
    begin
     xmltype_clob := '<a>123</a>';
     xmltype_obj := createxml(xmltype_clob);
     xmltype_str := xmltype_obj.getstringval();
     RAISE NOTICE 'xmltype_str is : %',xmltype_str;
    end;
    /
    NOTICE:  xmltype_str is : <a>123</a>
    
    NOTE:

    The maximum size of the input parameter of the CLOB type is 1 GB minus 1 byte.

  • createxml(blob, numeric [,varchar2,numeric ,numeric])

    Description: Statically creates the XMLType type. The input parameters are of the BLOB type.

    Parameters: The first parameter is the BLOB to be converted to XMLType (mandatory column). The second parameter is the character set ID of the input XML data (mandatory column). The third parameter is the optional schema URL used to make the input comply with the specified schema (optional column, which is empty by default and does not take effect currently). The fourth parameter is the flag indicating whether the instance is valid according to the given XML schema (optional column, which is 0 by default and does not take effect currently). The fifth parameter is the flag indicating whether the instance is well-formed (optional column, which is 0 by default and does not take effect currently).

    Return type: XMLType

    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    gaussdb=# declare
     xmltype_blob blob;
     xmltype_obj xmltype;
     xmltype_str varchar2(1000);
    begin
     xmltype_blob := xmltype('<a>123</a>').getblobval(7);
     xmltype_obj := createxml(xmltype_blob,7);
     xmltype_str := xmltype_obj.getstringval();
     RAISE NOTICE 'xmltype_str is : %',xmltype_str;
    end;
    /
    NOTICE:  xmltype_str is : <?xml version="1.0" encoding="UTF8"?>
    <a>123</a>
    
    NOTE:
    • The maximum size of input parameters of the BLOB type is 256 MB minus 1 byte.
    • The character set ID ranges from 1 to 41.
  • getblobval(xmltype, numeric)

    Description: Converts the XMLType type to the BLOB type. The xmltype().func() method can be called.

    Parameters: The first parameter is of the XMLType type, and the second parameter is the ID of the target character set to be converted.

    Return type: BLOB

    Example:
    1
    2
    3
    4
    5
    gaussdb=# SELECT getblobval(xmltype('<asd/>'),7);
                                            getblobval                                        
    ------------------------------------------------------------------------------------------
     3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D2255544638223F3E0A3C6173642F3E
    (1 row)
    
    xmltype ().func ():
    1
    2
    3
    4
    5
    gaussdb=# select xmltype('<asd/>').getblobVal(7);
                                           xmltypefunc                                        
    ------------------------------------------------------------------------------------------
     3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D2255544638223F3E0A3C6173642F3E
    (1 row)
    
    NOTE:

    The maximum length of the input parameter of the XMLType type is 256 MB minus 1 byte.

  • getclobval(xmltype)

    Description: Converts the XMLType type to the CLOB type. The xmltype().func() method can be called.

    Parameter: The input parameter is of the XMLType type.

    Return type: CLOB

    Example:
    1
    2
    3
    4
    5
    gaussdb=# SELECT getclobval(xmltype('<a>123</a>'));
     getclobval
    --------------
     <a>123</a>
    (1 row)
    
    xmltype ().func ():
    1
    2
    3
    4
    5
    gaussdb=# SELECT xmltype('<a>123</a>').getclobval();
     xmltypefunc
    --------------
     <a>123</a>
    (1 row)
    
  • getnumberval(xmltype)

    Description: Converts the XMLType type to the numeric type. The xmltype().func() method can be called.

    Parameter: The input parameter is of the XMLType type.

    Return type: numeric

    Example:
    1
    2
    3
    4
    5
    gaussdb=# SELECT getnumberval(xmltype('<a>123</a>').extract('/a/text()'));
     getnumberval
    --------------
               123
    (1 row)
    
    xmltype ().func ():
    1
    2
    3
    4
    5
    gaussdb=# SELECT xmltype('<a>123</a>').extract('/a/text()').getnumberval();
     xmltypefunc
    --------------
               123
    (1 row)
    

  • isfragment(xmltype)

    Description: Returns a result indicating whether the XMLType type is fragment (1) or document (0). The xmltype().func() method can be called.

    Parameter: The input parameter is of the XMLType type.

    Return type: numeric

    Example:
    1
    2
    3
    4
    5
    gaussdb=# SELECT isfragment(xmltype('<a>123</a>'));
     isfragment
    --------------
                 0
    (1 row)
    
    xmltype ().func ():
    1
    2
    3
    4
    5
    gaussdb=# SELECT xmltype('<a>123</a>').isfragment();
     xmltypefunc
    --------------
                 0
    (1 row)
    
  • xmltype(varchar2[,varchar2,numeric ,numeric])

    Description: Creates the XMLType type from the varchar2 type.

    Parameters: The first parameter is the character string to be converted to XMLType (mandatory column). The second parameter is the optional schema URL used to make the input comply with the specified schema (optional column, which is empty by default and does not take effect currently). The third parameter is the flag indicating whether the instance is valid according to the given XML schema (optional column, which is 0 by default and does not take effect currently). The fourth parameter is the flag indicating whether the instance is well-formed (optional column, which is 0 by default and does not take effect currently).

    Return type: XMLType

    Example:
    1
    2
    3
    4
    5
    gaussdb=# SELECT xmltype('<a>123</a>');
     xmltype
    --------------
     <a>123</a>
    (1 row)
    
    NOTE:
    • Different from that in database A, in PL/SQL, XMLType allows input parameters to be empty strings and returns NULL.
    • For character encoding, only UTF-8, GBK, and LATIN1 to LATIN10 are supported, and the version field can only be set to 1.x.
  • xmltype(clob [,varchar2,numeric ,numeric])

    Description: Creates the XMLType type from the CLOB type.

    Parameters: The first parameter is the CLOB to be converted to XMLType (mandatory column). The second parameter is the optional schema URL used to make the input comply with the specified schema (optional column, which is empty by default and does not take effect currently). The third parameter is the flag indicating whether the instance is valid according to the given XML schema (optional column, which is 0 by default and does not take effect currently). The fourth parameter is the flag indicating whether the instance is well-formed (optional column, which is 0 by default and does not take effect currently).

    Return type: XMLType

    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    gaussdb=# declare
     xmltype_clob clob;
     xmltype_obj xmltype;
     xmltype_str varchar2(1000);
    begin
     xmltype_clob := '<a>123</a>';
     xmltype_obj := xmltype(xmltype_clob);
     xmltype_str := xmltype_obj.getstringval();
     RAISE NOTICE 'xmltype_str is : %',xmltype_str;
    end;
    /
    NOTICE:  xmltype_str is : <a>123</a>
    
    NOTE:

    The maximum size of the input parameter of the CLOB type is 1 GB minus 1 byte.

  • xmltype(blob, numeric [,varchar2,numeric ,numeric])

    Description: Creates the XMLType type from the BLOB type.

    Parameters: The first parameter is the BLOB to be converted to XMLType (mandatory column). The second parameter is the character set ID of the input XML data. The third parameter is the optional schema URL used to make the input comply with the specified schema (optional column, which is empty by default and does not take effect currently). The fourth parameter is the flag indicating whether the instance is valid according to the given XML schema (optional column, which is 0 by default and does not take effect currently). The fifth parameter is the flag indicating whether the instance is well-formed (optional column, which is 0 by default and does not take effect currently).

    Return type: XMLType

    Example:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    gaussdb=# declare
     xmltype_blob blob;
     xmltype_obj xmltype;
     xmltype_str varchar2(1000);
    begin
     xmltype_blob := getblobval(createxml('<a>123</a>'),7);
     xmltype_obj := xmltype(xmltype_blob,7);
     xmltype_str := xmltype_obj.getstringval();
     RAISE NOTICE 'xmltype_str is : %',xmltype_str;
    end;
    /
    NOTICE:  xmltype_str is : <?xml version="1.0" encoding="UTF8"?>
    <a>123</a>
    
    NOTE:
    • The maximum size of input parameters of the BLOB type is 256 MB minus 1 byte.
    • The character set ID ranges from 1 to 41.
  • getstringval(xmltype)

    Description: Converts the XMLType to a string.

    Parameter: XMLType to be converted.

    Return type: varchar2

    The getstringval function can be called in either of the following ways:

    Example 1:

    gaussdb=# SELECT getstringval('<a>123<b>456</b></a>');
         getstringval
    ----------------------
     <a>123<b>456</b></a>
    (1 row)

    Example 2: The calling mode is compatible with the ORA syntax.

    gaussdb=# SELECT xmltype('<a>123<b>456</b></a>').getstringval();
         xmltypefunc
    ----------------------
     <a>123<b>456</b></a>
    (1 row)
  • getrootelement(xmltype)

    Description: Gets the root element of the XMLType type.

    Parameter: XMLType whose root element is to be obtained.

    Return type: varchar2

    The getrootelement function can be called in either of the following ways:

    Example 1:

    gaussdb=# SELECT getrootelement('<a>123<b>456</b></a>');
     getrootelement
    ----------------
     a
    (1 row)

    Example 2: The calling mode is compatible with the ORA syntax.

    gaussdb=# SELECT xmltype('<a>123<b>456</b></a>').getrootelement();
     xmltypefunc
    -------------
     a
    (1 row)
  • getnamespace(xmltype)

    Description: Gets the namespace of the XMLType top-level element.

    Parameter: XMLType whose namespace is to be obtained.

    Return type: varchar2

    The getnamespace function can be called in either of the following ways:

    Example 1:

    gaussdb=# SELECT getnamespace('<c:a xmlns:c="asd">123<d:b xmlns:d="qwe">456</d:b></c:a>');
     getnamespace
    --------------
     asd
    (1 row)

    Example 2: The calling mode is compatible with the ORA syntax.

    gaussdb=# SELECT xmltype('<c:a xmlns:c="asd">123<d:b xmlns:d="qwe">456</d:b></c:a>').getnamespace();
     xmltypefunc
    -------------
     asd
    (1 row)
  • existsnode(xmltype, varchar2[, varchar2])

    Description: Determines whether the XML node exists in XMLType based on the XPath expression. If the XML node exists, 1 is returned. Otherwise, 0 is returned.

    Parameters: XMLType to be queried, path of the XPath node to be queried, and namespace of the XPath path (If the input parameter has a namespace, aliases must be defined for both the XPath and namespace, as shown in example 3.)

    Return type: numeric

    The existsnode function can be called in either of the following ways:

    Example 1:

    gaussdb=# SELECT existsnode('<a>123<b>456</b></a>','/a/b');
     existsnode
    ------------
              1
    (1 row)

    Example 2: The calling mode is compatible with the ORA syntax.

    gaussdb=# SELECT xmltype('<a>123<b>456</b></a>').existsnode('/a/b');
     xmltypefunc
    -------------
               1
    (1 row)

    Example 3:

    gaussdb=# SELECT existsnode('<a:b xmlns:a="asd">123<c>456</c></a:b>','/a:b/c','xmlns:a="asd"');
     existsnode
    ------------
              1
    (1 row)

    Example 4: The calling mode is compatible with the ORA syntax.

    gaussdb=# SELECT xmltype('<a:b xmlns:a="asd">123<c>456</c></a:b>').existsnode('/a:b/c','xmlns:a="asd"');
     xmltypefunc
    -------------
               1
    (1 row)
  • extractxml(xmltype, varchar2[, varchar2])

    Description: Checks whether an XML node exists in the given XMLType based on the XPath expression. If yes, the XMLType containing the node is returned. If no, NULL is returned. The return value can be inserted into a table of the XMLType type.

    Parameters: XMLType to be queried, path of the XPath node to be queried, and namespace of the XPath path (If the input parameter has a namespace, aliases must be defined for both the XPath and namespace, as shown in example 3.)

    Return type: XMLType

    The extractxml function can be called in either of the following ways:

    Example 1:

    gaussdb=# SELECT extractxml('<a>123<b>456</b></a>','/a/b');
     extractxml
    ------------
     <b>456</b>
    (1 row)

    Example 2: The calling mode is compatible with the ORA syntax.

    gaussdb=# SELECT xmltype('<a>123<b>456</b></a>').extract('/a/b');
     xmltypefunc
    -------------
     <b>456</b>
    (1 row)
    
    gaussdb=# SELECT xmltype('<a>123<b>456</b></a>').extractxml('/a/b');
     xmltypefunc
    -------------
     <b>456</b>
    (1 row)

    Example 3:

    gaussdb=# SELECT extractxml('<a:b xmlns:a="asd">123<c>456</c></a:b>','/a:b','xmlns:a="asd"');
                   extractxml
    ----------------------------------------
     <a:b xmlns:a="asd">123<c>456</c></a:b>
    (1 row)

    Example 4: The calling mode is compatible with the ORA syntax.

    gaussdb=# SELECT xmltype('<a:b xmlns:a="asd">123<c>456</c></a:b>').extract('/a:b','xmlns:a="asd"');
                  xmltypefunc
    ----------------------------------------
     <a:b xmlns:a="asd">123<c>456</c></a:b>
    (1 row)
    
    gaussdb=# SELECT xmltype('<a:b xmlns:a="asd">123<c>456</c></a:b>').extractxml('/a:b','xmlns:a="asd"');
                  xmltypefunc
    ----------------------------------------
     <a:b xmlns:a="asd">123<c>456</c></a:b>
    (1 row)

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback