sql >> Base de Datos >  >> RDS >> Oracle

Recuperar imagen de Oracle DB

No estoy seguro de qué está haciendo lretorno.Load(...) para leer los datos, pero este ejemplo de código Sudo que usa una declaración de selección podría ayudarlo... Siempre tuve que obtener específicamente el blob y leerlo para obtener los bytes en el pasado.

Ejemplo para recuperar un LONG RAW Tipo de datos

var imgCmd = new OracleCommand("SELECT photo FROM photos WHERE photo_id = 1", _con);
imgCmd.InitialLONGFetchSize = -1; // Retrieve the entire image during select instead of possible two round trips to DB
var reader = imgCmd.ExecuteReader();
if (reader.Read()) {
    // Fetch the LONG RAW
    OracleBinary imgBinary = reader.GetOracleBinary(0);
    // Get the bytes from the binary obj
    byte[] imgBytes = imgBinary.IsNull ? null : imgBinary.Value;
}
reader.Close();

Ejemplo para recuperar un BLOB Tipo de datos

var imgCmd = new OracleCommand("SELECT photo FROM photos WHERE photo_id = 1", _con);
var reader = imgCmd.ExecuteReader();
if (reader.Read()) {
    // Fetch the blob
    OracleBlob imgBlob = reader.GetOracleBlob(0);
    // Create byte array to read the blob into
    byte[] imgBytes = new byte[imgBlob.Length];
    // Read the blob into the byte array
    imgBlob.Read(imgBytes, 0, imgBlob.Length);
}
reader.Close();