OracleLob.Read メソッド
現在の OracleLob ストリームからバイト シーケンスを読み取り、読み取ったバイト数の分だけストリーム内の位置を進めます。
名前空間: System.Data.OracleClient
アセンブリ: System.Data.OracleClient (system.data.oracleclient.dll 内)
構文
Public Overrides Function Read ( _ buffer As Byte(), _ offset As Integer, _ count As Integer _ ) As Integer
Dim instance As OracleLob Dim buffer As Byte() Dim offset As Integer Dim count As Integer Dim returnValue As Integer returnValue = instance.Read(buffer, offset, count)
- offset
現在のストリームから読み取ったデータの格納を開始する位置を示す buffer内のバイト オフセット。インデックス番号は 0 から始まります。CLOB 型および NCLOB 型の場合、これは偶数である必要があります。
戻り値
バッファに読み取られた合計バイト数。要求しただけのバイト数を読み取ることができなかった場合、この値は要求したバイト数より小さくなります。ストリームの末尾に到達した場合は 0 になることがあります。

例外の種類 | 条件 |
---|---|
ArgumentNullException | buffer が null 参照 (Visual Basic の場合は Nothing) です。 |
ArgumentOutOfRangeException | offset パラメータまたは count パラメータの値が正の値ではありません。 または オフセット パラメータとカウント パラメータの合計値が、バッファ長を超えています。 または |
InvalidOperationException | 操作がトランザクション内で実行されていないか、OracleLob オブジェクトが null か、または接続が閉じられています。 |
ObjectDisposedException | |
OracleException |

Read メソッドは、現在のストリームから最大で count で指定したバイト数だけ読み込み、読み込んだバイトを buffer 内の offset で始まる位置に格納します。ストリームの現在位置が、読み込んだバイト数だけ進みます。ただし、例外が発生した場合は、ストリーム内の現在位置はそのまま変わりません。Read は、読み込んだバイト数を返します。現在の位置がストリームの末尾である場合だけ、0 の値が返されます。読み取るデータがない場合、Read は、最低 1 バイトのデータを読み取ることができるまでブロックされます。現在の位置が LOB の末尾の場合に LOB から読み取ろうとした場合、Read は 0 を返します。ストリームの末尾に到達していない場合でも、Read は、必要なバイト数未満のデータを返すことができます。
.NET Framework Oracle 用データ プロバイダは、すべての CLOB データおよび NCLOB データを Unicode として処理します。したがって、CLOB 型および NCLOB 型では 1 文字が 2 バイトとなるため、これらにアクセスするときは常に複数のバイトを扱うことになります。たとえば、3 文字から成る文字列が、1 文字が 4 バイトの文字セットを使用している Oracle サーバーに NCLOB として保存されていて、Read 操作を実行する場合、文字列はサーバーに 12 バイトとして格納されていますが、文字列の長さは 6 バイトを指定します。
OracleLob オブジェクトを読み取る方法の C# の例を次に示します。
public static void ReadLobExample(OracleCommand command) { int actual = 0; //Select some data. // Table Schema: // "CREATE TABLE TableWithLobs (a int, b BLOB, c CLOB, d NCLOB)"; // "INSERT INTO TableWithLobs values (1, 'AA', 'AAA', N'AAAA')"; command.CommandText = "SELECT * FROM TableWithLobs"; OracleDataReader reader = command.ExecuteReader(); using(reader) { //Obtain the first row of data. reader.Read(); //Obtain the LOBs (all 3 varieties). OracleLob BLOB = reader.GetOracleLob(1); OracleLob CLOB = reader.GetOracleLob(2); OracleLob NCLOB = reader.GetOracleLob(3); //Example - Reading binary data (in chunks). byte[] buffer = new byte[100]; while((actual = BLOB.Read(buffer, 0, buffer.Length)) >0) Console.WriteLine(BLOB.LobType + ".Read(" + buffer + ", " + buffer.Length + ") => " + actual); //Example - Reading CLOB/NCLOB data (in chunks). //Note: You can read character data as raw Unicode bytes (using OracleLob.Read as in the above example). //However, because the OracleLob object inherits directly from the.NET stream object, //all the existing classes that manipluate streams can also be used. For example, the //.NET StreamReader makes converting the raw bytes into actual characters easier. StreamReader streamreader = new StreamReader(CLOB, Encoding.Unicode); char[] cbuffer = new char[100]; while((actual = streamreader.Read(cbuffer, 0, cbuffer.Length)) >0) Console.WriteLine(CLOB.LobType + ".Read(" + new string(cbuffer, 0, actual) + ", " + cbuffer.Length + ") => " + actual); //Example - Reading data (all at once). //You could use StreamReader.ReadToEnd to obtain all the string data,or simply //call OracleLob.Value to obtain a contiguous allocation of all the data. Console.WriteLine(NCLOB.LobType + ".Value => " + NCLOB.Value); } }
この形式を使用して、NULL の OracleLob を構築できます。
OracleLob myLob = OracleLob.Null;
この手法は主に、次の例が示すように、サーバーから返された LOB が NULL かどうかをテストするために使用します。
If(myLob == OracleLob.Null)
NULL の LOB は、0 バイトの LOB と同じように動作します。つまり、Read は成功し、常に 0 バイトを返します。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からOracleLob.Read メソッドを検索する場合は、下記のリンクをクリックしてください。

- OracleLob.Read メソッドのページへのリンク