question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Oracle. Cannot pass blob >=32 768 bytes as stored procedure parameter

See original GitHub issue
DataParameter a_data = new DataParameter("a_data", new byte[32768], DataType.Blob);
a_data.Size = alert.alert.photo.content.Length;
dataConnection.ExecuteProc("ProcedureName", new[] {  a_data });

ORA-01460: unimplemented or unreasonable conversion requested blob insert

Following code works:

var cmd = new OracleCommand("declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;");
cmd.Connection = (OracleConnection)dataConnection.Connection;

var param = new OracleParameter("tempblob", OracleDbType.Blob) { Direction = ParameterDirection.Output };
cmd.Parameters.Add(param);

cmd.ExecuteNonQuery();

var tempLob = (OracleBlob)param.Value;
tempLob.Write(new byte[32768], 0, 32768);

var comm = dataConnection.Connection.CreateCommand();
comm.CommandText = "ProcedureName";
comm.CommandType = CommandType.StoredProcedure;

var a_data = new OracleParameter("a_data", OracleDbType.Blob) { Value = tempLob };
comm.Parameters.Add(a_data );

comm.ExecuteNonQuery();

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
mrcopperbeardcommented, Mar 3, 2021

Found a workaround by specifying dbType as “BLOB” explicitly via constructor

new DataParameter("a_data", tempLob, "BLOB")

Many thanks to fellows from EF Core 😉

Update: Figured out that we can’t pass null this way. Thats why workaround became more tricky

var foo = tempLob == null
    ? DataParameter.Blob("a_data", tempLob)
    : new DataParameter("a_data", tempLob, "BLOB")
0reactions
jods4commented, Apr 10, 2021

Yes, there is another Github issue about having a true, generic, stream support. Disposal is a big issue and differences between dbs as well: when writing Oracle works in push fashion (you write into OracleBlob first); SqlServer works in a pull fashion (you pass a stream that is read by the sql provider).

In the meantime the ability to work with native DB types (e.g. OracleBlob) is a good enough stop-gap.

I found out that if you type your model property as OracleBlob you can read without problems:

class Frob
{
  public int Id { get; set }
  public OracleBlob Data { get; set; }
}

var row = db.Frobs.First(x => x.Id == 3);
// This is a perfectly usable OracleBlob that you can read as a stream.
var blob = row.Data;
// Don't forget to dispose.

But strangely something fishy happens if you try to write:

var frob = new Frob { Id = 1, Data = new OracleBlob(...) };
// Write into the blob
frob.Data.Write(...);
// Try to insert
db.Frobs.Insert(frob);
// Works, but not as you'd expect....

This write seems to work but as was observed in this issue, it also seems that the OracleBlob isn’t passed directly as a parameter value but rather is converted into a byte array. For instance, every byte is logged in the trace (should not be possible) and the OP here observed that values larger than 32k don’t go through (they should when using OracleBlob).

It’s probably just a small issue but if it worked it would unlock writing large blobs with Linq2Db.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When saving blob or clob 32KB or larger: ORA-01460: ...
I have a byte[] property mapped to an Oracle blob and a string property ... Cannot pass blob >=32 768 bytes as stored...
Read more >
ODP.NET blob PL/SQL parameter size limit? - Oracle Forums
I am trying to pass a blob into a PL/SQL procedure with the following method: cmd. ... ReadAllBytes("C:\\myfile.pdf"), ParameterDirection.
Read more >
Passing byte array as parameter to stored procedure in ...
BLOB to pass the data from your java application and you can consume it with the blob data type in your stored procedure....
Read more >
STORED PROCEDURE + OUTPUT PARAMETER + BLOB ...
Hi, I'm trying to use ODP.NET to retrieve a BLOB. I want to retrieve the BLOB using an output parameter of a Stored...
Read more >
Pass BLOBs to Oracle Stored Procedures
As it turns out, you can pass up to 32KB directly into a stored procedure BLOB parameter with no problems. It's when you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found