Search notes:

Oracle.DataAccess.Types.OracleBinary (class)

Oracle.DataAccess.Types.OracleBinary allows to access (long) raw data.
OracleBinary derives from System.ValueType.

Writing long raw data to file

The following example tries to demonstrate how long raw data can be extracted from a table and then be written to a file.
It turned out that setting the value InitialLONGFetchSize (in an Oracle.DataAccess.Client.OracleCommand object) to -1 was immensely valuable for this example because it allowed me to access the entire length of the underlying long raw, even if it was larger than 32 KB!
//   set ORACLE_HOME=c:\oracle\18c
//   copy %oracle_home%\ODP.NET\bin\4\Oracle.DataAccess.dll .
//   csc -reference:Oracle.DataAccess.dll writeLongRawToFile.cs

using System;
using System.Data;
using System.IO;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

class Prg {

   static void Main() {

      OracleConnection ora =  new OracleConnection($"user Id=rene;password=rene;data source=Ora18");
      ora.Open();
      OracleCommand    sql = new OracleCommand("select filename, image from tq84_sql_loader_long_raw", ora);
//    OracleCommand    sql = new OracleCommand("select filename, image from tableWithLongRaw", ora);
      sql.CommandType      = CommandType.Text;

   //
   // Following line is kind of crucial: it specifies that
   // the entire length of the long raw needs to be read:
   //
      sql.InitialLONGFetchSize  = -1;

      OracleDataReader rdr = sql.ExecuteReader();

      while (rdr.Read()) {
         String       filename = rdr.GetString    (0);
         OracleBinary image    = rdr.GetOracleBinary(1);

         Console.WriteLine($"{filename}: {image.Length} bytes");

         File.WriteAllBytes(filename, image.Value);
      }
   }
}
Github repository .NET-API, path: /Oracle/DataAccess/Types/OracleBinary/writeLongRawToFile.cs

See also

The corresponding class to access blobs is Oracle.DataAccess.Types.OracleBlob.

Index