OracleLob.Write(Byte[], Int32, Int32) 메서드

정의

현재 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부터 시작)입니다. CLOBNCLOB 데이터 형식의 경우 짝수여야 합니다.

count
Int32

현재 스트림에 쓸 바이트 수입니다. CLOBNCLOB 데이터 형식의 경우 짝수여야 합니다.

예외

buffer매개 변수가 null 참조(Visual Basic에서는 Nothing)인 경우

offset 또는 count 매개 변수의 값이 양수가 아닌 경우

또는

offsetcount 매개 변수의 합계가 buffer 길이보다 큰 경우

또는

count 또는 offset 매개 변수에 지정된 값이 0보다 작거나 4GB보다 큰 경우

또는

CLOBNCLOB 데이터 형식을 짝수 바이트로 지정해야 하는 경우

작업이 트랜잭션에 속하지 않거나, OracleLob 개체가 null이거나, 연결이 닫힌 경우

개체가 닫혔거나 삭제된 경우

Oracle 오류가 발생한 경우

설명

쓰기 작업이 성공하면 스트림 내의 위치가 작성된 바이트 수만큼 진행됩니다. 예외가 발생하면 스트림 내의 위치는 변경되지 않은 상태로 유지됩니다.

의 끝 LOB 부분을 벗어나는 쓰기는 허용되며 기록된 바이트 수만큼 을 확대합니다 LOB .

.NET Framework Data Provider for Oracle은 모든 CLOB 데이터와 NCLOB 데이터를 유니코드로 처리합니다. 따라서 및 NCLOB 데이터 형식에 CLOB 액세스할 때는 항상 각 문자가 2바이트인 바이트 수를 처리합니다. 예를 들어 문자 집합이 문자당 4바이트인 Oracle 서버에 3개의 문자가 포함된 텍스트 문자열을 로 저장 NCLOB 하고 작업을 수행하는 Write 경우 서버에 12바이트로 저장되지만 문자열의 길이를 6바이트로 지정합니다.

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();  
    }  
}  

참고

읽기 전용 LOB 쓰기 작업은 성공할 수 있지만 서버에서 을 LOB 업데이트하지는 않습니다. 그러나 이 경우 의 LOB 로컬 복사본이 업데이트됩니다. 따라서 나중에 개체에 대한 OracleLob 읽기 작업은 쓰기 작업의 결과를 반환할 수 있습니다.

적용 대상