Search notes:

OracleDataReader - GetBytes()

The method GetBytes() of the class Oracle.DataAccess.Client.OracleDataReader allows to select (read) binary data that is stored in a blob or long raw.

Simple example

The following example selects binary data from a blob or a long raw into a Byte[] and then writes the data into a file.
//   set ORACLE_HOME=c:\oracle\18c
//   copy %oracle_home%\ODP.NET\bin\4\Oracle.DataAccess.dll .
//   csc -reference:Oracle.DataAccess.dll GetBytes.cs

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

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 tq84_sql_loader_blob", ora);
      sql.CommandType      = CommandType.Text;

   //
   // InitialLONGFetchSize needed if data is select from a LONG RAW (but apparently not
   // if selected from a BLOB…)
   //
      sql.InitialLONGFetchSize  = -1;

      OracleDataReader rdr = sql.ExecuteReader();

      while (rdr.Read()) {
         String   filename = rdr.GetString(0);

      //
      // Call GetBytes() with a null Byte[] parameter in order to
      // get required length of data:
      //
         long     len      = rdr.GetBytes (1, 0, null, 0, 0);

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

      //
      // Get data as Byte[]:
      //
         Byte[] bytes =  new Byte[len];
         rdr.GetBytes(1, 0, bytes, 0, (int) len);

         File.WriteAllBytes(filename, bytes);
      }
   }
}
Github repository .NET-API, path: /Oracle/DataAccess/Client/OracleDataReader/GetBytes.cs
Two similar examples are using OracleBlob and using OracleBinary.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1759532751, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/dot-net/namespaces-classes/Oracle/DataAccess/Client/OracleDataReader/GetBytes(88): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78