一个最简单的C#调用ORACLE存储过程都出错,求教
ORACLE存储过程如下: 就是执行删除数据库存中一些数据
create or replace procedure WCL_2
(
tiaojian IN VARCHAR ,
result OUT NUMBER, -- '2' 成功,'1'失败
p_nErrCode OUT NUMBER,
p_vErrText OUT VARCHAR2
)
is
BEGIN
IF tiaojian ='1' THEN
delete from jcdbm_zddr a where a.zdsl=30;
END IF; --条件"1" 的 end if
Commit;
result := 2;
p_nErrCode := 0;
p_vErrText := '成功';
return;
EXCEPTION
--失败数据回滚,显示错误代码!
WHEN OTHERS THEN
Rollback;
result := 1;
p_nErrCode := SQLCODE;
p_vErrText := SQLERRM;
return;
END WCL_2;
C#代码如下:
private void button5_Click(object sender, EventArgs e)
{
OracleConnection conn = new OracleConnection(Dboperation.connectionstring);
OracleCommand cmd = new OracleCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "WCL_2";
OracleParameter param = new OracleParameter("tiaojian", OracleType.VarChar,10);
param.Direction = ParameterDirection.Input;
param.Value = "1";
cmd.Parameters.Add(param);
try
{
conn.Open();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
catch (OracleException ex)
{
string errorMessage = "Code: " + ex.Code + "\n" +
"Message: " + ex.Message + "\n" + ex.ErrorCode + "\n" + ex.Source + "\n" + ex.Data + "\n" + ex.InnerException + "\n" + ex.StackTrace + "\n" + ex.TargetSite + "\n";
MessageBox.Show(errorMessage);
//
}
conn.Close();
}
搞不懂,存储过程测试过都成功的,但是调用的时候提示参数个数或类型不对,出错画面如下:
errorMessage"Code: 6550\nMessage: ORA-06550: line 1, column 7:\nPLS-00306: wrong number or types of arguments in call to 'WCL_2'\nORA-06550: line 1, column 7:\nPL/SQL: Statement ignored\n\n-2146232008\nSystem.Data.OracleClient\nSystem.Collections.ListDictionaryInternal\n\n 在 System.Data.OracleClient.OracleConnection.CheckError(OciErrorHandle errorHandle, Int32 rc)\r\n 在 System.Data.OracleClient.OracleCommand.Execute(OciStatementHandle statementHandle, CommandBehavior behavior, Boolean needRowid, OciRowidDescriptor& rowidDescriptor, ArrayList& resultParameterOrdinals)\r\n 在 System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean needRowid, OciRowidDescriptor& rowidDescriptor)\r\n 在 System.Data.OracleClient.OracleCommand.ExecuteNonQuery()\r\n 在 yw.frm_mlqhyw.button5_Click(Object sender, EventArgs e) 位置 E:\\设计练习\\yw\\yw\\yw\\frm_mlqhyw.cs:行号 143\nVoid CheckError(System.Data.OracleClient.OciErrorHandle, Int32)\n"string
望高手能指教一下
[解决办法]
后面3个返回的参数,也要创建吧
我的异常网推荐解决方案:oracle存储过程,http://www.myexception.cn/oracle-develop/177537.html