Skip Headers
Oracle® Data Provider for .NET Developer's Guide
12c Release 1 (12.1.0.1.0)

Part Number E41125-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

OracleClob Class

An OracleClob is an object that has a reference to CLOB data. It provides methods for performing operations on CLOBs.

Note:

The OracleClob object uses the client side character set when retrieving or writing CLOB data using a .NET Framework byte array.

Class Inheritance

System.Object

  System.MarshalByRefObject

    System.IO.Stream

      Oracle.DataAccess.Types.OracleClob

Declaration

// C#
public sealed class OracleClob : Stream, ICloneable, INullable

Requirements

Provider ODP.NET, Unmanaged Driver ODP.NET, Managed Driver
Assembly Oracle.DataAccess.dll Oracle.ManagedDataAccess.dll
Namespace Oracle.DataAccess.Types Oracle.ManagedDataAccess.Types
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5 4.0, 4.5

Thread Safety

All public static methods are thread-safe, although instance methods do not guarantee thread safety.

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class OracleClobSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
 
    OracleClob clob = new OracleClob(con);        
 
    // Write 4 chars from writeBuffer, starting at buffer offset 0
    char[] writeBuffer = new char[4] {'a', 'b', 'c', 'd'};
    clob.Write(writeBuffer, 0, 4);
 
    // Append first 2 chars from writeBuffer {'a', 'b'} to the oracleClob
    clob.Append(writeBuffer, 0, 2);
 
    // Prints "clob.Length  = 12"
    Console.WriteLine("clob.Length  = " + clob.Length);
 
    // Reset the Position for the Read
    clob.Position = 0;
 
    // Read 6 chars into readBuffer, starting at buffer offset 0
    char[] readBuffer = new char[6];       
    int charsRead = clob.Read(readBuffer, 0, 6);
 
    // Prints "charsRead    = 6"
    Console.WriteLine("charsRead    = " + charsRead);    
 
    // Prints "readBuffer   = abcdab"
    Console.Write("readBuffer   = ");
    for(int index = 0; index <  readBuffer.Length; index++)
    {
      Console.Write(readBuffer[index]);
    }
    Console.WriteLine();
        
    // Search for the 2nd occurrence of a char pattern 'ab'
    // starting from char offset 0 in the OracleClob
    char[] pattern = new char[2] {'a', 'b'};
    long posFound = clob.Search(pattern, 0, 2);
 
    // Prints "posFound     = 5" 
    Console.WriteLine("posFound     = " + posFound);          
      
    // Erase 4 chars of data starting at char offset 1
    // Sets chars to ''
    clob.Erase(1, 4);
 
    //Prints "clob.Value   = a    b"
    Console.WriteLine("clob.Value   = " + clob.Value);
 
    clob.Close();
    clob.Dispose();
 
    con.Close();
    con.Dispose();
  }
}

OracleClob Members

OracleClob members are listed in the following tables.

OracleClob Constructors

OracleClob constructors are listed in Table 13-19.

Table 13-19 OracleClob Constructors

Constructor Description

OracleClob Constructors

Creates an instance of the OracleClob class bound to a temporary CLOB (Overloaded)


OracleClob Static Fields

OracleClob static fields are listed in Table 13-20.

Table 13-20 OracleClob Static Fields

Field Description

MaxSize

Holds the maximum number of bytes a CLOB can hold, which is 4,294,967,295 (2^32 - 1) bytes

Null

Represents a null value that can be assigned to the value of an OracleClob instance


OracleClob Static Methods

OracleClob static methods are listed in Table 13-21.

Table 13-21 OracleClob Static Methods

Methods Description

Equals

Inherited from System.Object (Overloaded)


OracleClob Instance Properties

OracleClob instance properties are listed in Table 13-22.

Table 13-22 OracleClob Instance Properties

Properties Description

CanRead

Indicates whether or not the LOB stream can be read

CanSeek

Indicates whether or not forward and backward seek operations can be performed

CanWrite

Indicates whether or not the LOB stream can be written

Connection

Indicates the OracleConnection that is used to retrieve and write CLOB data

IsEmpty

Indicates whether the CLOB is empty or not

IsInChunkWriteMode

Indicates whether or not the CLOB has been opened

IsNClob

Indicates whether or not the OracleClob object represents an NCLOB.

IsNull

Indicates whether or not the current instance has a null value

IsTemporary

Indicates whether or not the current instance is bound to a temporary CLOB

Length

Indicates the size of the CLOB data in bytes

OptimumChunkSize

Indicates the minimum number of bytes to retrieve or send from the database during a read or write operation

Position

Indicates the current read or write position in the LOB stream in bytes

Value

Returns the data, starting from the first character in the CLOB or NCLOB, as a string


OracleClob Instance Methods

The OracleClob instance methods are listed in Table 13-23.

Table 13-23 OracleClob Instance Methods

Methods Description

Append

Appends data to the current OracleClob instance (Overloaded)

BeginChunkWrite

Opens the CLOB

BeginRead

Inherited from System.IO.Stream

BeginWrite

Inherited from System.IO.Stream

Clone

Creates a copy of an OracleClob object

Close

Closes the current stream and releases resources associated with it

Compare

Compares data referenced by the current instance to that of the supplied object

CopyTo

Copies the data to an OracleClob (Overloaded)

CreateObjRef

Inherited from System.MarshalByRefObject

Dispose

Releases resources allocated by this object

EndChunkWrite

Closes the CLOB referenced by the current OracleClob instance

EndRead

Inherited from System.IO.Stream

EndWrite

Inherited from System.IO.Stream

Equals

Inherited from System.Object (Overloaded)

Erase

Erases the specified amount of data (Overloaded)

Flush

Not supported

GetHashCode

Returns a hash code for the current instance

GetLifetimeService

Inherited from System.MarshalByRefObject

GetType

Inherited from System.Object

InitializeLifetimeService

Inherited from System.MarshalByRefObject

IsEqual

Compares the LOB data referenced by two OracleClobs

Read

Reads from the current instance (Overloaded)

ReadByte

Inherited from System.IO.Stream

Search

Searches for a character pattern in the current instance of OracleClob (Overloaded)

Seek

Sets the position in the current LOB stream

SetLength

Trims or truncates the CLOB value

ToString

Inherited from System.Object

Write

Writes the provided buffer into the OracleClob (Overloaded)

WriteByte

Inherited from System.IO.Stream



OracleClob Constructors

OracleClob constructors create instances of the OracleClob class bound to a temporary CLOB.

Overload List:

  • OracleClob(OracleConnection)

    This constructor creates an instance of the OracleClob class bound to a temporary CLOB with an OracleConnection object.

  • OracleClob(OracleConnection, bool, bool)

    This constructor creates an instance of the OracleClob class that is bound to a temporary CLOB, with an OracleConnection object, a boolean value for caching, and a boolean value for NCLOB.

OracleClob(OracleConnection)

This constructor creates an instance of the OracleClob class bound to a temporary CLOB with an OracleConnection object.

Declaration

// C#
public OracleClob(OracleConnection con);

Parameters

  • con

    The OracleConnection object.

Exceptions

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The connection must be opened explicitly by the application. OracleClob does not open the connection implicitly. The temporary CLOB utilizes the provided connection to store CLOB data. Caching is not enabled by default.

OracleClob(OracleConnection, bool, bool)

This constructor creates an instance of the OracleClob class that is bound to a temporary CLOB, with an OracleConnection object, a boolean value for caching, and a boolean value for NCLOB.

Declaration

// C#
public OracleClob(OracleConnection con, bool bCaching, bool bNCLOB);

Parameters

  • con

    The OracleConnection object connection.

  • bCaching

    A flag that indicates whether or not server-side caching is enabled.

  • bNCLOB

    A flag that is set to true if the instance is a NCLOB or false if it is a CLOB.

Exceptions

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The connection must be opened explicitly by the application. OracleClob does not open the connection implicitly. The temporary CLOB or NCLOB uses the provided connection to store CLOB data.


OracleClob Static Fields

OracleClob static fields are listed in Table 13-24.

Table 13-24 OracleClob Static Fields

Field Description

MaxSize

Holds the maximum number of bytes a CLOB can hold, which is 4,294,967,295 (2^32 - 1) bytes

Null

Represents a null value that can be assigned to the value of an OracleClob instance


MaxSize

The MaxSize field holds the maximum number of bytes a CLOB can hold, which is 4,294,967,295 (2^32 - 1) bytes.

Declaration

// C#
public static readonly Int64 MaxSize = 4294967295;

Remarks

This field is useful in code that checks whether or not your operation exceeds the maximum length (in bytes) allowed.

Null

This static field represents a null value that can be assigned to the value of an OracleClob instance.

Declaration

// C#
public static readonly OracleClob Null;

OracleClob Static Methods

OracleClob static methods are listed in Table 13-25.

Table 13-25 OracleClob Static Methods

Methods Description

Equals

Inherited from System.Object (Overloaded)



OracleClob Instance Properties

OracleClob instance properties are listed in Table 13-26.

Table 13-26 OracleClob Instance Properties

Properties Description

CanRead

Indicates whether or not the LOB stream can be read

CanSeek

Indicates whether or not forward and backward seek operations can be performed

CanWrite

Indicates whether or not the LOB stream can be written

Connection

Indicates the OracleConnection that is used to retrieve and write CLOB data

IsEmpty

Indicates whether the CLOB is empty or not

IsInChunkWriteMode

Indicates whether or not the CLOB has been opened

IsNClob

Indicates whether or not the OracleClob object represents an NCLOB.

IsNull

Indicates whether or not the current instance has a null value

IsTemporary

Indicates whether or not the current instance is bound to a temporary CLOB

Length

Indicates the size of the CLOB data in bytes

OptimumChunkSize

Indicates the minimum number of bytes to retrieve or send from the database during a read or write operation

Position

Indicates the current read or write position in the LOB stream in bytes

Value

Returns the data, starting from the first character in the CLOB or NCLOB, as a string


CanRead

Overrides Stream

This instance property indicates whether or not the LOB stream can be read.

Declaration

// C#
public override bool CanRead{get;}

Property Value

If the LOB stream can be read, returns true; otherwise, returns false.

CanSeek

Overrides Stream

This instance property indicates whether or not forward and backward seek operations can be performed.

Declaration

// C#
public override bool CanSeek{get;}

Property Value

If forward and backward seek operations can be performed, returns true; otherwise, returns false.

CanWrite

Overrides Stream

This instance property indicates whether or not the LOB object supports writing.

Declaration

// C#
public override bool CanWrite{get;}

Property Value

If the LOB stream can be written, returns true; otherwise, returns false.

Connection

This instance property indicates the OracleConnection that is used to retrieve and write CLOB data.

Declaration

// C#
public OracleConnection Connection {get;}

Property Value

An OracleConnection.

Exceptions

ObjectDisposedException - The object is already disposed.

IsEmpty

This instance property indicates whether the CLOB is empty or not.

Declaration

// C#
public bool IsEmpty {get;}

Property Value

A bool.

Exceptions

ObjectDisposedException - The object is already disposed.

IsInChunkWriteMode

This instance property indicates whether or not the CLOB has been opened to defer index updates.

Declaration

// C#
public bool IsInChunkWriteMode{get;}

Property Value

If the CLOB has been opened, returns true; otherwise, returns false.

IsNClob

This instance property indicates whether or not the OracleClob object represents an NClob.

Declaration

// C#
public bool IsNClob {get;}

Property Value

A bool.

IsNull

This property indicates whether or not the current instance has a null value.

Declaration

// C#
public bool IsNull{get;}

Property Value

Returns true if the current instance has a null value; otherwise, returns false.

IsTemporary

This instance property indicates whether or not the current instance is bound to a temporary CLOB.

Declaration

// C#
public bool IsTemporary {get;}

Property Value

A bool.

Length

Overrides Stream

This instance property indicates the size of the CLOB data in bytes.

Declaration

// C#
public override Int64 Length {get;}

Property Value

An Int64 that indicates the size of the CLOB in bytes.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

OptimumChunkSize

This instance property indicates the minimum number of bytes to retrieve or send from the database during a read or write operation.

Declaration

// C#
public int OptimumChunkSize{get;}

Property Value

A number representing the minimum bytes to retrieve or send.

Exceptions

ObjectDisposedException - The object is already disposed.

Position

Overrides Stream

This instance property indicates the current read or write position in the LOB stream in bytes.

Declaration

// C#
public override Int64 Position{get; set;}

Property Value

An Int64 that indicates the read or write position.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The Position is less than 0.

Value

This instance property returns the data, starting from the first character in the CLOB or NCLOB, as a string.

Declaration

// C#
public string Value{get;}

Property Value

A string.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The Value is less than 0.

Remarks

The value of Position is neither used nor changed by using this property.

The maximum string length that can be returned by this property is 2 GB.


OracleClob Instance Methods

The OracleClob instance methods are listed in Table 13-27.

Table 13-27 OracleClob Instance Methods

Methods Description

Append

Appends data to the current OracleClob instance (Overloaded)

BeginChunkWrite

Opens the CLOB

BeginRead

Inherited from System.IO.Stream

BeginWrite

Inherited from System.IO.Stream

Clone

Creates a copy of an OracleClob object

Close

Closes the current stream and releases resources associated with it

Compare

Compares data referenced by the current instance to that of the supplied object

CopyTo

Copies the data to an OracleClob (Overloaded)

CreateObjRef

Inherited from System.MarshalByRefObject

Dispose

Releases resources allocated by this object

EndChunkWrite

Closes the CLOB referenced by the current OracleClob instance

EndRead

Inherited from System.IO.Stream

EndWrite

Inherited from System.IO.Stream

Equals

Inherited from System.Object (Overloaded)

Erase

Erases the specified amount of data (Overloaded)

Flush

Not supported

GetHashCode

Returns a hash code for the current instance

GetLifetimeService

Inherited from System.MarshalByRefObject

GetType

Inherited from System.Object

InitializeLifetimeService

Inherited from System.MarshalByRefObject

IsEqual

Compares the LOB data referenced by two OracleClobs

Read

Reads from the current instance (Overloaded)

ReadByte

Inherited from System.IO.Stream

Search

Searches for a character pattern in the current instance of OracleClob (Overloaded)

Seek

Sets the position in the current LOB stream

SetLength

Trims or truncates the CLOB value

ToString

Inherited from System.Object

Write

Writes the provided buffer into the OracleClob (Overloaded)

WriteByte

Inherited from System.IO.Stream


Append

This instance method appends data to the current OracleClob instance.

Overload List:

  • Append(OracleClob)

    This instance method appends the CLOB data referenced by the provided OracleClob object to the current OracleClob instance.

  • Append(byte [ ], int, int)

    This instance method appends data at the end of the CLOB, from the supplied byte array buffer, starting from offset (in bytes) of the supplied byte array buffer.

  • Append(char [ ], int, int)

    This instance method appends data from the supplied character array buffer to the end of the current OracleClob instance, starting at the offset (in characters) of the supplied character buffer.

Append(OracleClob)

This instance method appends the CLOB data referenced by the provided OracleClob object to the current OracleClob instance.

Declaration

// C#
public void Append(OracleClob obj);

Parameters

  • obj

    An OracleClob object.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The parameter has a different connection than the object, OracleConnection is not opened, or OracleConnection has been reopened.

Remarks

No character set conversions are made.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

Append(byte [ ], int, int)

This instance method appends data at the end of the CLOB, from the supplied byte array buffer, starting from offset (in bytes) of the supplied byte array buffer.

Declaration

// C#
public int Append(byte[] buffer, int offset, int count);

Parameters

  • buffer

    An array of bytes, representing a Unicode string.

  • offset

    The zero-based byte offset in the buffer from which data is read.

  • count

    The number of bytes to be appended.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - Either the offset or the count parameter is not even.

Remarks

Both offset and count must be even numbers for CLOB and NCLOB because every two bytes represent a Unicode character.

Append(char [ ], int, int)

This instance method appends data from the supplied character array buffer to the end of the current OracleClob instance, starting at the offset (in characters) of the supplied character buffer.

Declaration

// C#
public void Append(char[] buffer, int offset, int count);

Parameters

  • buffer

    An array of characters.

  • offset

    The zero-based offset (in characters) in the buffer from which data is read.

  • count

    The number of characters to be appended.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class AppendSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
 
    OracleClob clob = new OracleClob(con);
      
    // Append 2 chars {'d', 'e'} to the OracleClob
    char[] buffer = new char[3] {'d', 'e', 'f'};
    clob.Append(buffer, 0, 2);
 
    // Prints "clob.Value = de"
    Console.WriteLine("clob.Value = " + clob.Value);
     
    clob.Close();
    clob.Dispose();
 
    con.Close();
    con.Dispose();
  }
}

BeginChunkWrite

This instance method opens the CLOB.

Declaration

// C#
public void BeginChunkWrite();

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

BeginChunkWrite does not need to be called before manipulating the CLOB data. This is provided for performance reasons.

After this method is called, write operations do not cause the domain or function-based index on the column to be updated. Index updates occur only once after EndChunkWrite is called.

Clone

This instance method creates a copy of an OracleClob object.

Declaration

// C#
public object Clone();

Return Value

An OracleClob object.

Implements

ICloneable

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

The cloned object has the same property values as that of the object being cloned.

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class CloneSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
 
    OracleClob clob1 = new OracleClob(con);
 
    // Prints "clob1.Position = 0"
    Console.WriteLine("clob1.Position = " + clob1.Position);
    
    // Set the Position before calling Clone()
    clob1.Position = 1;
 
    // Clone the OracleClob
    OracleClob clob2 = (OracleClob)clob1.Clone();    
    
    // Prints "clob2.Position = 1"
    Console.WriteLine("clob2.Position = " + clob2.Position);
 
    clob1.Close(); 
    clob1.Dispose();
 
    clob2.Close();
    clob2.Dispose();
 
    con.Close();
    con.Dispose();
  }
}

Close

Overrides Stream

This instance method closes the current stream and releases resources associated with it.

Declaration

// C#
public override void Close();

Compare

This instance method compares data referenced by the current instance to that of the supplied object.

Declaration

// C#
public int Compare(Int64 src_offset, OracleClob obj, Int64 dst_offset, 
   Int64 amount);

Parameters

  • src_offset

    The comparison starting point (in characters) for the current instance.

  • obj

    The provided OracleClob object.

  • dst_offset

    The comparison starting point (in characters) for the provided OracleClob.

  • amount

    The number of characters to compare.

Return Value

The method returns a value that is:

  • Less than zero: if the data referenced by the current instance is less than that of the supplied instance.

  • Zero: if both objects reference the same data.

  • Greater than zero: if the data referenced by the current instance is greater than that of the supplied instance.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The parameter has a different connection than the object, OracleConnection is not opened, or OracleConnection has been reopened.

ArgumentOutOfRangeException - Either the src_offset, dst_offset, or amount parameter is less than 0.

Remarks

The character set of the two OracleClob objects being compared should be the same for a meaningful comparison.

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

CopyTo

CopyTo copies data from the current instance to the provided OracleClob object.

Overload List:

  • CopyTo(OracleClob)

    This instance method copies data from the current instance to the provided OracleClob object.

  • CopyTo(OracleClob, Int64)

    This instance method copies data from the current OracleClob instance to the provided OracleClob object with the specified destination offset.

  • CopyTo(Int64, OracleClob, Int64, Int64)

    This instance method copies data from the current OracleClob instance to the provided OracleClob object with the specified source offset, destination offset, and character amounts.

CopyTo(OracleClob)

This instance method copies data from the current instance to the provided OracleClob object.

Declaration

// C#
public Int64 CopyTo(OracleClob obj);

Parameters

  • obj

    The OracleClob object to which the data is copied.

Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

  • The OracleConnection is not open or has been closed during the lifetime of the object.

  • The LOB object parameter has a different connection than the object.

Remarks

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

CopyTo(OracleClob, Int64)

This instance method copies data from the current OracleClob instance to the provided OracleClob object with the specified destination offset.

Declaration

// C#
public Int64 CopyTo(OracleClob obj, Int64 dst_offset);

Parameters

  • obj

    The OracleClob object to which the data is copied.

  • dst_offset

    The offset (in characters) at which the OracleClob object is copied.

Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

ArgumentOutOfRangeException - The dst_offset is less than 0.

InvalidOperationException - This exception is thrown if any of the following conditions exist:

  • The OracleConnection is not open or has been closed during the lifetime of the object.

  • The LOB object parameter has a different connection than the object.

Remarks

If the dst_offset is beyond the end of the OracleClob data, spaces are written into the OracleClob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection; that is, the same OracleConnection object.

CopyTo(Int64, OracleClob, Int64, Int64)

This instance method copies data from the current OracleClob instance to the provided OracleClob object with the specified source offset, destination offset, and character amounts.

Declaration

// C#
public Int64 CopyTo(Int64 src_offset,OracleClob obj,Int64 dst_offset,
    Int64 amount);

Parameters

  • src_offset

    The offset (in characters) in the current instance, from which the data is read.

  • obj

    The OracleClob object to which the data is copied.

  • dst_offset

    The offset (in characters) at which the OracleClob object is copied.

  • amount

    The amount of data to be copied.

Return Value

The return value is the amount copied.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The parameter has a different connection than the object, OracleConnection is not opened, or OracleConnection has been reopened.

ArgumentOutOfRangeException - The src_offset, the dst_offset, or the amount parameter is less than 0.

Remarks

If the dst_offset is beyond the end of the OracleClob data, spaces are written into the OracleClob until the dst_offset is met.

The offsets are 0-based. No character conversion is performed by this operation.

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class CopyToSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
    
    OracleClob clob1 = new OracleClob(con);
    OracleClob clob2 = new OracleClob(con);
      
    // Write 4 chars, starting at buffer offset 0
    char[] buffer = new char[4] {'a', 'b', 'c', 'd'};    
    clob1.Write(buffer, 0, 4);
 
    // Copy 2 chars from char 0 of clob1 to char 1 of clob2
    clob1.CopyTo(0, clob2, 1, 2);
    
    //Prints "clob2.Value =  ab"
    Console.WriteLine("clob2.Value = " + clob2.Value);
        
    clob1.Close(); 
    clob1.Dispose();
 
    clob2.Close();
    clob2.Dispose();
 
    con.Close();
    con.Dispose();
  }
}

Dispose

This instance method releases resources allocated by this object.

Declaration

public void Dispose();

Implements

IDisposable

Remarks

The object cannot be reused after being disposed. Although some properties can still be accessed, their values cannot be accountable. Since resources are freed, method calls can lead to exceptions.

EndChunkWrite

This instance method closes the CLOB referenced by the current OracleClob instance.

Declaration

// C#
public void EndChunkWrite();

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

Index updates occur immediately if write operation(s) are deferred by the BeginChunkWrite method.

Erase

Erase erases part or all data.

Overload List:

  • Erase()

    This instance method erases all data.

  • Erase(Int64, Int64)

    This instance method replaces the specified amount of data (in characters) starting from the specified offset with zero-byte fillers (in characters).

Erase()

This instance method erases all data.

Declaration

// C#
public Int64 Erase();

Return Value

The number of characters erased.

Erase(Int64, Int64)

This instance method replaces the specified amount of data (in characters) starting from the specified offset with zero-byte fillers (in characters).

Declaration

// C#
public Int64 Erase(Int64 offset, Int64 amount);

Parameters

  • offset

    The offset.

  • amount

    The amount of data.

Return Value

The actual number of characters erased.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The offset or amount parameter is less than 0.

GetHashCode

Overrides Object

This method returns a hash code for the current instance.

Declaration

// C#
public override int GetHashCode();

Return Value

An int representing a hash code.

IsEqual

This instance method compares the LOB data referenced by two OracleClobs.

Declaration

// C#
public bool IsEqual(OracleClob obj);

Parameters

  • obj

    An OracleClob object.

Return Value

Returns true if the current OracleClob and the provided OracleClob refer to the same LOB. Otherwise, returns false.

Remarks

Note that this method can return true even if the two OracleClob objects returns false for == or Equals() because two different OracleClob instances can refer to the same LOB.

The provided object and the current instance must be using the same connection, that is, the same OracleConnection object.

Read

Read reads a specified amount from the current instance and populates the array buffer.

Overload List:

  • Read(byte [ ], int, int)

    This instance method reads a specified amount of bytes from the current instance and populates the byte array buffer.

  • Read(char [ ], int, int)

    This instance method reads a specified amount of characters from the current instance and populates the character array buffer.

Read(byte [ ], int, int)

Overrides Stream

This instance method reads a specified amount of bytes from the current instance and populates the byte array buffer.

Declaration

// C#
public override int Read(byte [] buffer, int offset, int count);

Parameters

  • buffer

    The byte array buffer that is populated.

  • offset

    The offset (in bytes) at which the buffer is populated.

  • count

    The amount of bytes to be read.

Return Value

The number of bytes read from the CLOB.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

Both offset and count must be even numbers for CLOB and NCLOB because every two bytes represent a Unicode character.

The LOB data is read starting from the position specified by the Position property, which must also be an even number.

OracleClob is free to return fewer bytes than requested, even if the end of the stream has not been reached.

Read(char [ ], int, int)

This instance method reads a specified amount of characters from the current instance and populates the character array buffer.

Declaration

// C#
public int Read(char[ ] buffer, int offset, int count);

Parameters

  • buffer

    The character array buffer that is populated.

  • offset

    The offset (in characters) at which the buffer is populated.

  • count

    The amount of characters to be read.

Return Value

The return value indicates the number of characters read from the CLOB.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

  • The offset or the count is less than 0.

  • The offset is greater than or equal to the buffer.Length.

  • The offset and the count together are greater than buffer.Length.

Remarks

Handles all CLOB and NCLOB data as Unicode.

The LOB data is read starting from the position specified by the Position property.

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class ReadSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
 
    OracleClob clob = new OracleClob(con);
    
    // Write 3 chars, starting at buffer offset 1
    char[] writeBuffer = new char[4] {'a', 'b', 'c', 'd'};
    clob.Write(writeBuffer, 1, 3);
 
    // Reset the Position (in bytes) for Read
    clob.Position = 2;
 
    // Read 2 chars into buffer starting at buffer offset 1
    char[] readBuffer = new char[4];    
    int charsRead = clob.Read(readBuffer, 1, 2);
 
    // Prints "charsRead  = 2"
    Console.WriteLine("charsRead  = " + charsRead);    
 
    // Prints "readBuffer =  cd "
    Console.Write("readBuffer = ");
    for(int index = 0; index <  readBuffer.Length; index++)
    {
      Console.Write(readBuffer[index]);
    }
    Console.WriteLine();
    
    clob.Close();
    clob.Dispose();
 
    con.Close();
    con.Dispose();
  }
}

Search

Search searches for a character pattern in the current instance of OracleClob.

Overload List:

Search(byte[ ], Int64, Int64)

This instance method searches for a character pattern, represented by the byte array, in the current instance of OracleClob.

Declaration

// C#
public int Search(byte[] val, Int64 offset, Int64 nth);

Parameters

  • val

    A Unicode byte array.

  • offset

    The 0-based offset (in characters) starting from which the OracleClob is searched.

  • nth

    The specific occurrence (1-based) of the match for which the absolute offset (in characters) is returned.

Return Value

Returns the absolute offset of the start of the matched pattern (in bytes) for the nth occurrence of the match. Otherwise, 0 is returned.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

  • The offset is less than 0.

  • The nth is less than or equal to 0.

  • The nth is greater than or equal to OracleClob.MaxSize.

  • The offset is greater than or equal to OracleClob.MaxSize.

Remarks

The byte[ ] is converted to Unicode before the search is made.

The limit of the search pattern is 16383 bytes.

Search(char[ ], Int64, Int64)

This instance method searches for a character pattern in the current instance of OracleClob.

Declaration

// C#
public Int64 Search(char [ ] val, Int64 offset, Int64 nth);

Parameters

  • val

    The Unicode string being searched for.

  • offset

    The 0-based offset (in characters) starting from which the OracleClob is searched.

  • nth

    The specific occurrence (1-based) of the match for which the absolute offset (in characters) is returned.

Return Value

Returns the absolute offset of the start of the matched pattern (in characters) for the nth occurrence of the match. Otherwise, 0 is returned.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

  • The offset is less than 0.

  • The nth is less than or equal to 0.

  • The val.Length doubled is greater than 16383.

  • The nth is greater than or equal to OracleClob.MaxSize.

  • The offset is greater than or equal to OracleClob.MaxSize.

Remarks

The limit of the search pattern is 16383 bytes.

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class SearchSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
 
    OracleClob clob = new OracleClob(con);
    
    // Write 7 chars, starting at buffer offset 0
    char[] buffer = new char[7] {'a', 'b', 'c', 'd', 'a', 'b', 'c'};
    clob.Write(buffer, 0, 7);
      
    // Search for the 2nd occurrence of a char pattern 'bc'
    // starting at offset 1 in the OracleBlob
    char[] pattern = new char[2] {'b', 'c'};
    long posFound = clob.Search(pattern, 1, 2);
 
    // Prints "posFound = 6" 
    Console.WriteLine("posFound = " + posFound);
          
    clob.Close();
    clob.Dispose();
 
    con.Close();
    con.Dispose();
  }
}

Seek

Overrides Stream

This instance method sets the position on the current LOB stream.

Declaration

// C#
public override Int64 Seek(Int64 offset, SeekOrigin origin);

Parameters

  • offset

    A byte offset relative to origin.

  • origin

    A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.

Return Value

Returns an Int64 that indicates the position.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

Remarks

If offset is negative, the new position precedes the position specified by origin by the number of characters specified by offset.

If offset is zero, the new position is the position specified by origin.

If offset is positive, the new position follows the position specified by origin by the number of characters specified by offset.

SeekOrigin.Begin specifies the beginning of a stream.

SeekOrigin.Current specifies the current position within a stream.

SeekOrigin.End specifies the end of a stream.

SetLength

Overrides Stream

This instance method trims or truncates the CLOB value to the specified length (in characters).

Declaration

// C#
public override void SetLength(Int64 newlen);

Parameters

  • newlen

    The desired length of the current stream in characters.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - The newlen parameter is greater than 0.

Write

This instance method writes data from the provided array buffer into the OracleClob.

Overload List:

Write(byte[ ], int, int)

Overrides Stream

This instance method writes data from the provided byte array buffer into the OracleClob.

Declaration

// C#
public override void Write(byte[ ] buffer, int offset, int count);

Parameters

  • buffer

    The byte array buffer that represents a Unicode string.

  • offset

    The offset (in bytes) from which the buffer is read.

  • count

    The amount of data (in bytes) from the buffer to be written into the OracleClob.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

  • The offset or the count is less than 0.

  • The offset is greater than or equal to the buffer.Length.

  • The offset and the count together are greater than the buffer.Length.

  • The offset, the count, or the Position is not even.

Remarks

Both offset and count must be even numbers for CLOB and NCLOB because every two bytes represent a Unicode character.

The LOB data is read starting from the position specified by the Position property. The Position property must be an even number.

If necessary, proper data conversion is carried out from the client character set to the database character set.

Write(char[ ], int, int)

This instance method writes data from the provided character array buffer into the OracleClob.

Declaration

// C#
public void Write(char[ ] buffer, int offset, int count);

Parameters

  • buffer

    The character array buffer that is written to the OracleClob.

  • offset

    The offset (in characters) from which the buffer is read.

  • count

    The amount (in characters) from the buffer that is to be written into the OracleClob.

Exceptions

ObjectDisposedException - The object is already disposed.

InvalidOperationException - The OracleConnection is not open or has been closed during the lifetime of the object.

ArgumentOutOfRangeException - This exception is thrown if any of the following conditions exist:

  • The offset or the count is less than 0.

  • The offset is greater than or equal to the buffer.Length.

  • The offset and the count together are greater than buffer.Length.

  • The Position is not even.

Remarks

Handles all CLOB and NCLOB data as Unicode.

The LOB data is read starting from the position specified by the Position property.

If necessary, proper data conversion is carried out from the client character set to the database character set.

Example

// C#
 
using System;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
 
class WriteSample
{
  static void Main()
  {
    string constr = "User Id=scott;Password=tiger;Data Source=oracle";
    OracleConnection con = new OracleConnection(constr);
    con.Open();
 
    OracleClob clob = new OracleClob(con);
      
    // Set the Position for the Write;
    clob.Position = 0;
 
    // Begin ChunkWrite to improve performance
    // Index updates occur only once after EndChunkWrite
    clob.BeginChunkWrite();         
      
    // Write to the OracleClob in 5 chunks of 2 chars each
    char[] c = new char[2] {'a', 'b'};
    for (int index = 0; index < 5; index++)
    {
      clob.Write(c, 0, c.Length);
    }
    clob.EndChunkWrite();
 
    // Prints "clob.Value = ababababab"
    Console.WriteLine("clob.Value = " + clob.Value);
 
    clob.Close();
    clob.Dispose();
 
    con.Close();
    con.Dispose();
  }
}