Oracle存储过程无法从ASP.NET调用

时间:2015-12-31 08:04:51

标签: asp.net oracle ado.net

我在ASP.NET中编写了一个代码来从Oracle存储过程中获取数据。但是在尝试获取数据时出现错误:

  

ORA-06550:第1行第7列:PLS-00306:调用'USER_FEEDBACK'ORA-06550时参数的数量或类型错误:第1行第7行:PL / SQL:忽略语句

程序代码是这样的:

create or replace PROCEDURE user_feedback(cv_results out sys_refcursor,start_date IN VARCHAR2)
IS
BEGIN
 open cv_results for
select pi.first_name || ' ' || pi.last_name initiator
 ......
from request_workflow w inner join request_workflow_attribute waRating
on waRating.request_workflow_id = w.row_id
and waRating.attr_name = 'UserRating'
.............
where w.date_stamp_utc between start_date and '31-dec-2015'
order by waRating.attr_value desc, eform_name;
END ;

这是我的ASP.NET代码:

Oracle.DataAccess.Client.OracleCommand objCmd = new Oracle.DataAccess.Client.OracleCommand();
objCmd.Connection = objConn;
objCmd.CommandText = "user_feedback";
objCmd.CommandType = CommandType.StoredProcedure;

Oracle.DataAccess.Client.OracleParameter oraP = new Oracle.DataAccess.Client.OracleParameter();

//   System.Data.OracleClient.OracleParameter op = null; 
oraP.OracleDbType = OracleDbType.RefCursor;
oraP.ParameterName = "cv_results";
oraP.Direction = System.Data.ParameterDirection.Output;

oraP.ParameterName = "start_date";
oraP.OracleDbType = OracleDbType.Varchar2;

oraP.Value = "01-Dec-2015";
oraP.Direction = System.Data.ParameterDirection.Input;
objCmd.Parameters.Add(oraP);

objConn.Open();
objCmd.ExecuteReader();
objCmd.ExecuteNonQuery();

请建议如何使其发挥作用。

2 个答案:

答案 0 :(得分:1)

您只需创建/添加单个参数,但会使用不同的值分配两次,从而只会调用一个参数。

相反,创建并添加两个单独的参数,例如;

var oraP1 = new Oracle.DataAccess.Client.OracleParameter();

oraP1.OracleDbType = OracleDbType.RefCursor;
oraP1.ParameterName = "cv_results";
oraP1.Direction = System.Data.ParameterDirection.Output;

objCmd.Parameters.Add(oraP1);

var oraP2 = new Oracle.DataAccess.Client.OracleParameter();

oraP2.ParameterName = "start_date";
oraP2.OracleDbType = OracleDbType.Varchar2;
oraP2.Value = "01-Dec-2015";
oraP2.Direction = System.Data.ParameterDirection.Input;

objCmd.Parameters.Add(oraP2);

答案 1 :(得分:0)

可能是因为你没有Add第一个参数。尝试这样的事情?

...
oraP.ParameterName = "cv_results";
oraP.Direction = System.Data.ParameterDirection.Output;
objCmd.Parameters.Add(oraP);

oraP = new Oracle.DataAccess.Client.OracleParameter();
oraP.ParameterName = "start_date";
...

但是,如果你以后要从该refcursor读取,那么为第一个参数声明另一个变量会更好。