将一个字节序列写入当前 OracleLob 流,并使流中的当前位置前进所写入的字节数。Writes a sequence of bytes to the current OracleLob stream, and advances the current position within this stream by the number of bytes written.
public:
override void Write(cli::array <: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
字节数组。An array of bytes. 此方法将 count 中指定的字节数从 buffer 复制到当前流中。This method copies the number of bytes specified in count from buffer to the current stream.
offset
buffer 中的从零开始的字节偏移量,从此处开始将字节复制到当前流。The zero-based byte offset in buffer at which to begin copying bytes to the current stream. 对于 CLOB 和 NCLOB 数据类型,它必须为偶数。For CLOB and NCLOB data types, this must be an even number.
count
要写入当前流的字节数。The number of bytes to be written to the current stream. 对于 CLOB 和 NCLOB 数据类型,它必须为偶数。For CLOB and NCLOB data types, this must be an even number.
例外
buffer 参数为 null 引用(在 Visual Basic 中为 Nothing)。The buffer parameter is a null reference (Nothing in Visual Basic).
offset 或 count 参数中的值为非正。A value in the offset or count parameter is not positive.
- 或 --or-
offset 参数与 count 参数之和大于 buffer 的长度。The sum of the offset and count parameters is larger than the buffer length.
- 或 --or-
count 或 offset 参数中指定的值小于零,或大于 4 GB。A value specified in the count or offset parameter is less than zero or greater than 4 gigabytes.
- 或 --or-
必须将 CLOB 和 NCLOB 数据类型指定为偶数字节数。You must specify CLOB and NCLOB data types as an even number of bytes.
该操作未处在事务中,OracleLob 对象为 null,或者连接已关闭。The operation is not within a transaction, the OracleLob object is null, or the connection is closed.
对象已关闭或已释放。The object was closed or disposed.
发生了 Oracle 错误。An Oracle error has occurred.
注解
如果写入操作成功,则流中的位置将按写入的字节数向前推进。If the write operation is successful, the position within the stream advances by the number of bytes written. 如果发生异常,则流中的位置将保持不变。If an exception occurs, the position within the stream remains unchanged.
允许超出末尾的写入 LOB ,并 LOB 按写入的字节数放大。Writing beyond the end of LOB is allowed and enlarges the LOB by the number of bytes written.
用于 Oracle 的 .NET Framework 数据提供程序 CLOB NCLOB 以 Unicode 形式处理所有和数据。The .NET Framework Data Provider for Oracle handles all CLOB and NCLOB data as Unicode. 因此,在访问 CLOB 和 NCLOB 数据类型时,始终会处理字节数,其中每个字符为2个字节。Therefore, when accessing CLOB and NCLOB data types, you are always dealing with the number of bytes, where each character is 2 bytes. 例如,如果一串包含三个字符的文本 NCLOB 在 Oracle 服务器上另存为,其中字符集为每个字符4个字节,并且你执行 Write 操作,则可以将该字符串的长度指定为6个字节,尽管它在服务器上存储为12个字节。For example, if a string of text containing three characters is saved as an NCLOB on an Oracle server where the character set is 4 bytes per character, and you perform a Write operation, you specify the length of the string as 6 bytes, although it is stored as 12 bytes on the server.
若要写入 LOB ,您必须 LOB 使用 SQL SELECT 语句中的 FOR UPDATE 子句检索到,并且必须已启动本地事务。To write to the LOB, you must have retrieved the LOB using the FOR UPDATE clause in the SQL SELECT statement, and you must have a local transaction started.
下面的示例演示如何写入 OracleLob 对象:The following example demonstrates how to write to OracleLob objects:
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();
}
}
备注
对只读的写入操作 LOB 可能会成功,但不会更新 LOB 服务器上的。A write operation to a read-only LOB might succeed, but does not update the LOB on the server. 但在这种情况下,将更新的本地副本 LOB 。In this case, however, the local copy of the LOB is updated. 因此,以后对对象的读取操作 OracleLob 可能会返回写入操作的结果。Therefore, later read operations on the OracleLob object might return the results of the write operation.
适用于