用代碼說明解決方法.
在Oracle有一個存儲過程,在用Oracle工具(Quest Toad)調試執行時沒有任何問題,當在C#中調用此過程報Oracle-06550錯誤.
一般的此存儲過程具有調用參數.
具體代碼:
Oracle後臺的存儲過程代碼:
Create Or Replace Procedure Lungu.Pro_Alert_Lunguid(In_LunguID varchar2)
Is
---Local Var定義區
Var_Sequence Number;
N Number;
N1 Number;
N2 Number;
NN number;
/******************************************************************************/
Begin
If(In_Lunguid <>' ') Then
Select Count(*) Into N From Robot_Alart_R2_Lunguid Where Lunguid=In_Lunguid;
If(N>=1) Then
Update Robot_Alart_R2_Lunguid Set Alert_Flag = '1' Where Lunguid=In_Lunguid;
End If;
select count(*) into NN From R2_Plan
Where State_Of_Order<>'4' ;
if(NN>=1) then
Var_Sequence := To_Number(Substr(In_Lunguid,5));
For Cc In
(
Select Plan_Order_Id,Prodord_Id,Acual_Output,State_Of_Order From R2_Plan
Where State_Of_Order<>'4' Order By Start_Date Desc
)
Loop
N1:=To_Number(Substr(Cc.Prodord_Id,5,5));
N2:=N1+Cc.Acual_Output;
If(Var_Sequence>=N1) And (Var_Sequence<=N2) Then
Select Count(*) Into N From R2_Plan Where Prodord_Id=Cc.Prodord_Id;
If(N>=1) Then
If(Cc.State_Of_Order='2') Then
Update R2_Plan Set State_Of_Order = '4'
Where Prodord_Id<Cc.Prodord_Id
And State_Of_Order='3';
Update R2_Plan Set State_Of_Order = '3'
Where Prodord_Id=Cc.Prodord_Id;
End If;
End If;
End If;
End Loop ;
end if;
End If;
Exception
When Others Then
-- Consider Logging The Error And Then Re-Raise
Raise;
End Pro_Alert_Lunguid;
此過程在Oracle中執行沒有任何問題.
在C#中的調用代碼:
using (OracleConnection tmpOraConn = new OracleConnection(this.oraConn.ConnectionString))
{
tmpOraConn.Open();
OracleCommand tmpCmd = tmpOraConn.CreateCommand();
tmpCmd.CommandText = "Pro_ALERT_LUNGUID";
tmpCmd.CommandType = CommandType.StoredProcedure;
tmpCmd.Parameters.Add("LunguID", OracleType.NVarChar);
tmpCmd.Parameters["LunguID"].Direction = ParameterDirection.Input;
tmpCmd.Parameters["LunguID"].Value = this.initialLunguID;
try
{
tmpCmd.ExecuteNonQuery();
}
catch (OracleException oe)
{
string errorMsg = oe.Message;
}
finally
{
tmpOraConn.Close();
tmpCmd = null;
}
執行此段代碼就會報Oracle-06650錯誤.
解決辦法:
注意到Oracle存儲過程Pro_Alert_Lunguid(In_lunguId in varchar2)中的參數名爲in_lunguID.
而在C#中 tmpCmd.Parameters.Add("LunguID", OracleType.NVarChar);中添加的參數名爲LunguID.問題就出在這兒. 要保持C#中添加的參數名和Oracle中後臺存儲過程名一致(也就是兩個的參數名一樣)
只要將上面的C#中的代碼 tmpCmd.Parameters.Add("LunguID", OracleType.NVarChar);改爲
tmpCmd.Parameters.Add("In_LunguID", OracleType.NVarChar);即可.當然也可以將Oracle的存儲過程的參數從
in_Lunguid改爲--->lunguID.