OracleLob.Write(Byte[], Int32, Int32) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の OracleLob ストリームにバイト シーケンスを書き込み、書き込まれたバイト数だけこのストリーム内の現在の位置を進めます。
public:
override void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public override void Write(byte[] buffer, int offset, int count);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (buffer As Byte(), offset As Integer, count As Integer)
パラメーター
- buffer
- Byte[]
バイトの配列。 このメソッドは、 count で指定されたバイト数を buffer から現在のストリームにコピーします。
- offset
- Int32
現在のストリームへのバイトのコピーを開始する buffer の 0 から始まるバイト オフセット。
CLOBとNCLOBのデータ型の場合、これは偶数である必要があります。
- count
- Int32
現在のストリームに書き込まれるバイト数。
CLOBとNCLOBのデータ型の場合、これは偶数である必要があります。
例外
buffer パラメーターは null 参照 (Visual Basic では Nothing) です。
offsetまたは count パラメーターの値が正ではありません。
-または-
offsetパラメーターと count パラメーターの合計が、bufferの長さを超えています。
-または-
count または offset パラメーターで指定された値が 0 未満か、4 ギガバイトを超える値です。
-または-
CLOBデータ型とNCLOBデータ型を偶数バイトとして指定する必要があります。
操作がトランザクション内にありません。 OracleLob オブジェクトが null であるか、接続が閉じられています。
オブジェクトが閉じられたか、破棄されました。
Oracle エラーが発生しました。
注釈
書き込み操作が成功した場合、ストリーム内の位置は書き込まれたバイト数だけ進みます。 例外が発生した場合、ストリーム内の位置は変更されません。
LOBの末尾を超えた書き込みが許可され、書き込まれたバイト数だけLOBが拡大されます。
.NET Framework for Oracle Data Providerは、すべての CLOB および NCLOB データを Unicode として処理します。 したがって、 CLOB および NCLOB データ型にアクセスする場合は、常にバイト数を処理します。各文字は 2 バイトです。 たとえば、3 文字を含むテキストの文字列が、文字セットが 1 文字あたり 4 バイトである Oracle サーバー上の NCLOB として保存され、 Write 操作を実行する場合、文字列の長さは 6 バイトとして指定しますが、サーバーには 12 バイトとして格納されます。
LOBに書き込むには、SQL SELECT ステートメントで FOR UPDATE 句を使用してLOBを取得し、ローカル トランザクションを開始する必要があります。
次の例では、 OracleLob オブジェクトに書き込む方法を示します。
public static void WriteLobExample(OracleCommand command)
{
// Note: Updating LOB data requires a transaction.
command.Transaction = command.Connection.BeginTransaction();
// Select some data.
// Table Schema:
// "CREATE TABLE tablewithlobs (a int, b BLOB, c BLOB)";
// "INSERT INTO tablewithlobs values (1, 'AA', 'AAA')";
command.CommandText = "SELECT * FROM TableWithLobs FOR UPDATE";
OracleDataReader reader = command.ExecuteReader();
using(reader)
{
// Obtain the first row of data.
reader.Read();
// Obtain both LOBs.
OracleLob BLOB1 = reader.GetOracleLob(1);
OracleLob BLOB2 = reader.GetOracleLob(2);
// Perform any desired operations on the LOB, (read, position, and so on).
// ...
// Example - Writing binary data (directly to the backend).
// To write, you can use any of the stream classes, or write raw binary data using
// the OracleLob write method. Writing character vs. binary is the same;
// however note that character is always in terms of Unicode byte counts
// (for example: even number of bytes - 2 bytes for every Unicode character).
var buffer = new byte[100];
buffer[0] = 0xCC;
buffer[1] = 0xDD;
BLOB1.Write(buffer, 0, 2);
BLOB1.Position = 0;
Console.WriteLine(BLOB1.LobType + ".Write(" + buffer + ", 0, 2) => " + BLOB1.Value);
// Example - Copying data into another LOB.
long actual = BLOB1.CopyTo(BLOB2);
Console.WriteLine(BLOB1.LobType + ".CopyTo(" + BLOB2.Value + ") => " + actual);
// Commit the transaction now that everything succeeded.
// Note: On error, Transaction.Dispose is called (from the using statement)
// and will automatically roll-back the pending transaction.
command.Transaction.Commit();
}
}
Note
読み取り専用 LOB への書き込み操作は成功する可能性がありますが、サーバー上の LOB は更新されません。 ただし、この場合は、 LOB のローカル コピーが更新されます。 そのため、 OracleLob オブジェクトに対する後の読み取り操作は、書き込み操作の結果を返す可能性があります。