从C#错误运行Oracle存储过程

时间:2012-10-08 07:50:22

标签: c# oracle stored-procedures

我是oracle的新手。我创建了一个存储过程来获取表数据。

create or replace
procedure GETLATESTNEWS(cv_results in out sys_refcursor)
as
begin
open cv_results for
select news from tbl_newsdetails;
EXCEPTION
 WHEN OTHERS THEN
  ROLLBACK;
  RAISE_APPLICATION_ERROR(-99999,'Not Inserted due to :'||SQLERRM);  
end;

程序编译成功。但在我的.net代码中我收到错误

ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GETLATESTNEWS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

我的.net代码是

con.ConnectionString = constring;
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "GETLATESTNEWS";
cmd.CommandType = CommandType.StoredProcedure;
rdr = cmd.ExecuteReader();

可能是什么问题?我能够插入插入存储过程。但选择不起作用。

2 个答案:

答案 0 :(得分:1)

尝试添加:

cmd.Parameters.Add("cv_results", OracleDbType.RefCursor).Direction = ParameterDirection.Output;

答案 1 :(得分:0)

我用过这个,它对我有用

OracleCommand oraCommand = new OracleCommand();
oraCommand.Connection = oraConnection;
oraCommand.CommandType = CommandType.StoredProcedure;
oraCommand.CommandText = "procedurename";
OracleParameter oraParameter = new OracleParameter(":result", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
oraCommand.Parameters.Add(oraParameter);
oraCommand.ExecuteNonQuery();

OracleDataAdapter oraDataAdapter = new OracleDataAdapter(oraCommand);
Oracle.DataAccess.Types.OracleRefCursor refCursor = (Oracle.DataAccess.Types.OracleRefCursor)oraParameter.Value;
OracleDataReader reader = refCursor.GetDataReader();

但是如果将存储过程作为ref_cursor返回。