Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET2.0 C# Oracle
How to fetch records using C#.Net and ODBC from a Oracle Stored Procedure which has Output parameters as cursor?
 
I have a stored procedure sp_myproc which has a cursor as a ouput parameters.
 
In my application , I'm using ODBC for connection to Oracle.
The Problem is ,there is no such type of odbctype for cursor .
 
so, How can I get records?
 
OdbcConnection odbcCon = new OdbcConnection(connectionString);
OdbcCommand odbcCmd = new OdbcCommand();
odbcCmd.CommandText = "SP_myOracle";
odbcCmd.CommandType = CommandType.StoredProcedure;
//here I want to Add parameters as Cursor and Directon as Output

//
 DataTable dt = new DataTable();
 OdbcDataAdapter adap = new OdbcDataAdapter(odbcCmd);
 adap.Fill(dt);
 
my Stored Procedure is:
 
create or replace
PROCEDURE SP_myOracle
(EmpDETAILSCURSOR OUT  SYS_REFCURSOR)
AS
BEGIN
 OPEN EmpDETAILSCURSOR for 
Select EMP_NAME from Emp;
END
 
Thanks.
Posted 3-Sep-12 1:33am
ashriv942
Edited 3-Sep-12 1:34am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

static void Main(string[] args)
{
  string constr = "User Id=hr; Password=hr;
    Data Source=oramag; Pooling=false";
 
  OracleConnection con = new OracleConnection(constr);
  con.Open();
 
  OracleCommand cmd = con.CreateCommand();
 
  cmd.CommandText = "begin open :1 for
    select * from employees
    where manager_id=101; end;";
 
  OracleParameter p_rc = cmd.Parameters.Add(
    "p_rc",
    OracleDbType.RefCursor,
    DBNull.Value,
    ParameterDirection.Output);
 
  cmd.ExecuteNonQuery();
 
  cmd.Parameters.Clear();
 
  cmd.CommandText = "cursor_in_out.process_cursor";
  
  cmd.CommandType = CommandType.StoredProcedure;
 
  OracleParameter p_input = cmd.Parameters.Add(
    "p_input",
    OracleDbType.RefCursor,
    p_rc.Value,
    ParameterDirection.Input);
 
  cmd.ExecuteNonQuery();
 
  p_input.Dispose();
  p_rc.Dispose();
  cmd.Dispose();
  con.Dispose();
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 380
2 OriginalGriff 236
3 Gihan Liyanage 210
4 kbrandwijk 204
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 405
4 thatraja 370


Advertise | Privacy | Mobile
Web02 | 2.8.140902.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100