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[]
位元組陣列。 此方法將 中countbuffer指定的位元組數複製到目前串流。
- offset
- Int32
以零為基礎的位元組偏移量 buffer ,從哪裡開始將位元組複製到當前串流。 對於 CLOB 和 NCLOB 資料型態,這個數字必須是偶數。
- count
- Int32
目前串流要寫入的位元組數。 對於 CLOB 和 NCLOB 資料型態,這個數字必須是偶數。
例外狀況
或offset參數中的count值並非正值。
-或-
和offset參數的count和大於buffer長度。
-或-
或參數中指定的countoffset值小於零或大於4 GB。
-或-
你必須指定 CLOB 和 資料 NCLOB 型別為偶數位元組。
操作不在交易中、 OracleLob 物件為空,或連線已關閉。
該物件被封閉或棄置。
發生了神諭錯誤。
備註
若寫入成功,串流中的位置會依照寫入的位元組數前進。 若發生例外,串流中的位置保持不變。
允許寫入超過的 LOB 部分,並可 LOB 放大寫入的位元組數。
Oracle 的 .NET Framework Data Provider 以 Unicode 形式處理所有 CLOB 和 NCLOB 資料。 因此,存取 CLOB 資料 NCLOB 型別時,你總是處理位元組數,每個字元為 2 位元組。 例如,若一串包含三個字元的文字串被儲存為 , NCLOB 且該伺服器的字元集為每個字元為 4 位元組,並執行 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 可能會回傳寫入操作的結果。