1

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

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();

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

4

2 回答 2

1

尝试添加:

cmd.Parameters.Add("cv_results", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
于 2012-10-08T08:33:50.237 回答
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 返回。

于 2012-10-08T09:09:13.663 回答