OracleBlobクラス
OracleBlobオブジェクトは、BLOBデータへの参照が含まれるオブジェクトです。このオブジェクトは、BLOBに対して操作を実行するためのメソッドを提供します。
クラスの継承
System.Object
System.MarshalByRefObject
System.IO.Stream
Oracle.DataAccess.Types.OracleBlob
宣言
// C# public sealed class OracleBlob : Stream, ICloneable, INullable
要件
| プロバイダ | ODP.NET管理対象外ドライバ | ODP.NET管理対象ドライバ | ODP.NET Core |
|---|---|---|---|
|
アセンブリ |
|
|
|
|
ネームスペース |
|
|
|
|
.NET Framework |
3.5, 4.5, 4.6, 4.7, 4.8 |
4.5, 4.6, 4.7, 4.8 |
4.6.1以降 |
|
.NET Core |
- |
- |
2.1以降 |
スレッド安全性
パブリック静的メソッドはスレッドセーフですが、インスタンス・メソッドではスレッド安全性は保証されません。
例
// C#
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
class OracleBlobSample
{
static void Main()
{
string constr = "User Id=scott;Password=tiger;Data Source=oracle";
OracleConnection con = new OracleConnection(constr);
con.Open();
OracleBlob blob = new OracleBlob(con);
// Write 4 bytes from writeBuffer, starting at buffer offset 0
byte[] writeBuffer = new byte[4] {1, 2, 3, 4};
blob.Write(writeBuffer, 0, 4);
// Append first 2 bytes from writeBuffer {1, 2} to the oracleBlob
blob.Append(writeBuffer, 0, 2);
// Prints "blob.Length = 6"
Console.WriteLine("blob.Length = " + blob.Length);
// Reset the Position for the Read
blob.Position = 0;
// Read 6 bytes into readBuffer, starting at buffer offset 0
byte[] readBuffer = new byte[6];
int bytesRead = blob.Read(readBuffer, 0, 6);
// Prints "bytesRead = 6"
Console.WriteLine("bytesRead = " + bytesRead);
// Prints "readBuffer = 123412"
Console.Write("readBuffer = ");
for(int index = 0; index < readBuffer.Length; index++)
{
Console.Write(readBuffer[index]);
}
Console.WriteLine();
// Search for the 2nd occurrence of a byte pattern '12'
// starting from byte offset 0 in the OracleBlob
byte[] pattern = new byte[2] {1, 2};
long posFound = blob.Search(pattern, 0, 2);
// Prints "posFound = 5"
Console.WriteLine("posFound = " + posFound);
// Erase 4 bytes of data starting at byte offset 1
// Sets bytes to zero
blob.Erase(1, 4);
byte[] erasedBuffer = blob.Value;
//Prints "erasedBuffer = 100002"
Console.Write("erasedBuffer = ");
for(int index = 0; index < erasedBuffer.Length; index++)
{
Console.Write(erasedBuffer[index]);
}
Console.WriteLine();
blob.Close();
blob.Dispose();
con.Close();
con.Dispose();
}
}