简体   繁体   中英

ODP.NET Implement Cursor for SELECT statement

如何使用ODP.NET在基本的SELECT statement like 'SELECT * FROM Employees'上实现简单的游标提取?

So it's quite straightforward.

First create OracleConnection class like this

OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);

con.Open();  //opens connection

Then you define and OracleCommand instance first by passing either raw query/stored procedure as first argument like

So in your particular case it would be OracleCommand cmd = new OracleCommand("SELECT * FROM Employees", con

if (con.State == ConnectionState.Open)
{
using (OracleCommand cmd = new OracleCommand(<query>/<stored proc>, con))
{    
cmd.CommandType = CommandType.StoredProcedure;  //in case of stored proc
cmd.BindByName = true;

OracleDataReader reader;
try
  {
    reader = cmd.ExecuteReader();    
    while(reader.Read())
    {
        Console.WriteLine("field: {0}", reader.GetDecimal(0));  
    }    
  }
catch (OracleException e)
  {
  foreach (OracleError err in e.Errors)
    {
       //print errors         
     }
   }
 con.Close(); 
 con.Dispose();
}
}

Here is the example http://www.oracle.com/technetwork/articles/dotnet/williams-refcursors-092375.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM