Getting RefCursor and VarChar outputs from the same Stored Procedure

♀尐吖头ヾ 提交于 2019-12-12 22:22:41

问题


I am new to Oracle, so please be gentle...

I am querying an existing Oracle DB using C# and ODP11 in .NET 4. All procedures up to this point have been, well, painful to figure out at first, but mostly "just worked" once i figured what i was doing... this one is a different story...

I have a stored proc that takes 4 parameters: 2 inputs and 2 outputs... the 2 inputs are grand. one of the outputs is a Varchar2 and the other is a refcursor.

I am using an OracleDataReader to run the query, like i have with any other proc that returns a RefCursor, but in this one, reader.Read() constantly returns false and i get no data. The other Output variable does, however, contain data (a string).

I have tried using reader.NextResult() but that returns false too, and my reader.Read() still returns false...

I can confirm that running the proc using Toad returns the correct result set...

Any ideas? What am i doing wrong?

Thanks.


回答1:


Ok, so after a lot more digging, i found the solution.

The original code was using ExecuteReader. I have changed it to run ExecuteNonQuery.

I pass the same parameters and types in as i did (2 inputs, 2 outputs, one of which is a string, one a refcursor).

When ExecuteNonQuery runs, i can see the value of the 3rd param (the string). then i do the following:

OracleDataReader dr = ((OracleRefCursor)pRefcursor.Value).GetDataReader();

Then i can do my usual loops with the dr! Happy days!



来源:https://stackoverflow.com/questions/16981951/getting-refcursor-and-varchar-outputs-from-the-same-stored-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!