Skip to Main Content

Breadcrumb

Question and Answer

Thanks for the question.

Asked: September 01, 2021 - 6:02 pm UTC

Last updated: September 01, 2021 - 6:02 pm UTC

Version:

Viewed 1000+ times

You Asked

Is it possible to send an array of either XmlDocument or XElement from the app tier (c#) to a package (oracle 18c) expecting a table of XMLTYPE? I have a collection of documents that are being fetched periodically, those documents need to be stored, then parsed and compared to records in the database. It's inefficient and slow to save individual docs over the wire to the db, so I'm trying to send the collection in its entirety from the app tier to the db. Also, the docs are quite large, greater than 32767 characters. Or is there another way that might be better?

The following unsuccessful code gives me ORA-03120: two-task conversion routine: integer overflow.

create table schema_owner.t1 (
id raw(16) default sys_guid() not null,
dtimported date default sysdate not null,
processed number(1,0) default 0 not null,
xmldoc xmltype)
xmltype xmldoc store as binary xml
tablespace schema_owner_data;

create or replace package schema_owner.pkg_event_data as
TYPE T_ASSOCIATIVE_ARRAY IS TABLE OF XMLTYPE INDEX BY PLS_INTEGER;
procedure load_data(documents t_associative_array);
end;

create or replace package body schema_owner.pkg_event_data is
procedure load_data(documents t_associative_array) is
begin
forall i in documents.first..documents.last
insert into schema_owner.t1(xmldoc) values(documents(i));
end;
end;

public async Task SaveBlobCollection(IList docs)
{
using (var command = connection.CreateCommand())
{
try
{
await command.Connection.OpenAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

var parm = command.Parameters.Add("blobcol", OracleDbType.XmlType);
parm.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
var arr = new XElement[docs.Count];
for (var index = 0; index < arr.Length; index++) arr[index] = docs[index];
parm.Value = arr;
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = "schema_owner.pkg_event_data.load_data";
try
{
command.ExecuteNonQuery();
} catch (Exception ex)
{
Console.WriteLine(ex.message);
}
}
}

Thanks!

and we said...

You can't bind an XMLTYPE with either parameter array binding nor an associative array. The only option I can think of is using BulkCopy with a CLOB to store your XML document. BulkCopy is available with unmanaged ODP.NET now and will be available with managed ODP.NET with the next DB release.


Is this answer out of date? If it is, please let us know via a Comment

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here