Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net 5 multiple out refcursor #207

Closed
odyyudah opened this issue Oct 9, 2021 · 2 comments
Closed

.net 5 multiple out refcursor #207

odyyudah opened this issue Oct 9, 2021 · 2 comments

Comments

@odyyudah
Copy link

odyyudah commented Oct 9, 2021

Can we please have a sample how does .net 5 run a stored procedure with multiple out refcursor?
Currently there is only a sample where .net 3.1 run a stored procedure with only one out refcursor.

@odyyudah odyyudah closed this as completed Oct 9, 2021
@odyyudah odyyudah reopened this Oct 9, 2021
@alexkeh
Copy link
Member

alexkeh commented Oct 10, 2021

Here's a sample .NET 5 console app that can be run against the HR sample schema:

     static void Main(string[] args)
    {
        string conString = "User Id=<User>;Password=<Password>;Data Source=<Data Source>;";

        try
        {

           OracleConnection con = new OracleConnection();
            con.ConnectionString = conString;
            con.Open();

            OracleCommand cmd = con.CreateCommand();

            string cmdtxt = "DECLARE a NUMBER:= 20; " +
              "BEGIN " +
              "OPEN :1 for select first_name,department_id from employees where department_id = 10; " +
              "OPEN :2 for select first_name,department_id from employees where department_id = a; " +
              "OPEN :3 for select first_name,department_id from employees where department_id = 30; " +
              "END;";

            cmd = new OracleCommand(cmdtxt, con);
            cmd.CommandType = CommandType.Text;

             OracleParameter p1 = cmd.Parameters.Add("refcursor1",
              OracleDbType.RefCursor);
            p1.Direction = ParameterDirection.Output;

            OracleParameter p2 = cmd.Parameters.Add("refcursor2",
              OracleDbType.RefCursor);
            p2.Direction = ParameterDirection.Output;

            OracleParameter p3 = cmd.Parameters.Add("refcursor3",
              OracleDbType.RefCursor);
            p3.Direction = ParameterDirection.Output;

            cmd.ExecuteNonQuery();

            // Let's retrieve data from the 2nd and 3rd result sets
            OracleDataReader dr1 =
              ((OracleRefCursor)cmd.Parameters[2].Value).GetDataReader();
            OracleDataReader dr2 =
              ((OracleRefCursor)cmd.Parameters[1].Value).GetDataReader();

            // Let's retrieve both DataReaders at the same time
            while (dr1.Read() && dr2.Read())
            {
                Console.WriteLine("Employee Name: " + dr1.GetString(0) + ", " +
                  "Employee Dept:" + dr1.GetDecimal(1));
                Console.WriteLine("Employee Name: " + dr2.GetString(0) + ", " +
                  "Employee Dept:" + dr2.GetDecimal(1));
                Console.WriteLine();
            }

            Console.WriteLine("Press 'Enter' to continue");
            Console.ReadLine();
        }
        catch (OracleException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

@alexkeh
Copy link
Member

alexkeh commented Oct 10, 2021

If you're asking about EF Core 5, this is a known issue in the ORM itself.
dotnet/efcore#8127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants