My Oracle Support Banner

OCI sample code to Write/Read Large XML Document into Xmltype Column (Doc ID 1296105.1)

Last updated on JUNE 27, 2023

Applies to:

Oracle Database - Enterprise Edition - Version and later
Gen 1 Exadata Cloud at Customer (Oracle Exadata Database Cloud Machine) - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Cloud Exadata Service - Version N/A and later
Oracle Database Cloud Schema Service - Version N/A and later
Information in this document applies to any platform.


Provides Sample Code on how to insert a Large XML document into an XMLType column/table using OCI.


SQL*loader with DIRECT PATH load is the fastest/recommended way to load large amounts of XML data into XMLTYPE column/table. Check Doc ID 163297.1

When XML document is > 4k, inserting a XML as a text string using OCI fails with ORA-1461.

To overcome the 4k limitation the CLOB should be built using the OCI API below.

and then insert the CLOB into XMLTYPE column/table.

This example expands on the sample program
$ORACLE_HOME/rdbms/demo/cdemoxml.c by adding code to load the LOB from a file of
variable length.

Note also that XML files can be inserted via a combination of the  XDK for C and OCI -
an example is included in
Section A of the Appendixes to the XML DB Developer Guide under:
 Loading XML Data using C (OCI) 


To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!

In this Document
 Sample Code
 Sample Output

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.