This documentation is archived and is not being maintained.

OracleCommand Class

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Represents an SQL statement or stored procedure to execute against a database. This class cannot be inherited.

For a list of all members of this type, see OracleCommand Members.


[Visual Basic]
NotInheritable Public Class OracleCommand
   Inherits Component
   Implements ICloneable, IDbCommand
public sealed class OracleCommand : Component, ICloneable,
public __gc __sealed class OracleCommand : public Component,
   ICloneable, IDbCommand
public class OracleCommand extends Component implements ICloneable,

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


The OracleCommand class provides the following methods for executing commands against a data source:

Item Description
ExecuteReader Executes commands that return rows.
ExecuteOracleNonQuery Executes an SQL statement against the Connection and returns the number of rows affected.
ExecuteNonQuery Executes commands such as SQL INSERT, DELETE, UPDATE, and SET statements.
ExecuteScalar Retrieves a single value (for example, an aggregate value) from a database as a .NET Framework data type.
ExecuteOracleScalar Retrieves a single value (for example, an aggregate value) from a database as an Oracle-specific data type.

You can reset the CommandText property and reuse the OracleCommand object.

If execution of the command results in a fatal OracleException, the OracleConnection may close. However, the user can reopen the connection and continue.

Note   Unlike the Command object in the other .NET Framework data providers (SQL Server, OLE DB, and ODBC), OracleCommand does not support a CommandTimeout property. Setting a command timeout has no effect and value returned is always zero.


[Visual Basic, C#, C++] The following example uses the ExecuteReader method of OracleCommand, along with OracleDataReader and OracleConnection, to select rows from a table.

[Visual Basic] 
Public Sub ReadMyData(myConnString As String)
    Dim mySelectQuery As String = "SELECT EmpNo, DeptNo FROM Emp"
    Dim myConnection As New OracleConnection(myConnString)
    Dim myCommand As New OracleCommand(mySelectQuery, myConnection)
    Dim myReader As OracleDataReader = myCommand.ExecuteReader()
        While myReader.Read()
            Console.WriteLine(myReader.GetInt32(0) & ", " _
               & myReader.GetInt32(1))
        End While
        ' always call Close when done reading.
        ' always call Close when done reading.
    End Try
End Sub

public void ReadMyData(string myConnString) 
   string mySelectQuery = "SELECT EmpNo, DeptNo FROM Emp";
   OracleConnection myConnection = new OracleConnection(myConnString);
   OracleCommand myCommand = new OracleCommand(mySelectQuery,myConnection);
   OracleDataReader myReader = myCommand.ExecuteReader();
     while (myReader.Read()) 
       Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetInt32(1));
    // always call Close when done reading.
    // always call Close when done reading.

void ReadMyData(String* myConnString) 
   String* mySelectQuery = S"SELECT EmpNo, DeptNo FROM Emp";
   OracleConnection* myConnection = new OracleConnection(myConnString);
   OracleCommand* myCommand = new OracleCommand(mySelectQuery,myConnection);
   OracleDataReader* myReader = myCommand->ExecuteReader();
     while (myReader->Read()) 
       Console::WriteLine(S"{0}, {1}", __box(myReader->GetInt32(0)), __box(myReader->GetInt32(1)));
    // always call Close when done reading.
    // always call Close when done reading.

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Data.OracleClient

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Data.Oracleclient (in System.Data.Oracleclient.dll)

See Also

OracleCommand Members | System.Data.OracleClient Namespace | OracleDataAdapter | OracleConnection