0

这是我的程序,它通过 PL/SQL Developer 工作:

create or replace procedure CHECK_INFO_INS
(
    p_id_aircraft IN VARCHAR2,           
    p_id_check_type IN NUMBER,     
    p_last_check   IN DATE,             
    p_next_check   IN DATE,             
    p_expectedcost IN NUMBER,                             
    p_id_currency  IN NUMBER,
    p_currency_rate IN NUMBER                         
)             
is
Rate number;
CurrentDate Date;
catID Checkcategories.Id%type;
begin
select C.ID into catID from CHECKCATEGORIES C WHERE C.NAME='C' and C.CHECKTYPEID = p_id_check_type;

  Rate:=round(p_expectedcost/MONTHS_BETWEEN(p_next_check, p_last_check),3)*p_currency_rate;
  CurrentDate := SYSDATE;
  INSERT INTO CHECK_INFO
  (
      id_check_info,            
      id_aircraft,              
      id_check_categories,      
      last_check,               
      next_check,              
      expectedcost,             
      is_accumulation_complited,
      rate,                     
      id_currency,              
      current_date,             
      monthes_between,
      CURENCY_RATE             
 )
  values
  (
    CHECKS_INFO_SEQ.NEXTVAL,
    p_id_aircraft,
    catID,
    p_last_check,
    p_next_check,
    p_expectedcost,
    0,
    Rate,
    p_id_currency,
    CurrentDate,
    round(MONTHS_BETWEEN(p_next_check, p_last_check),1),
    p_currency_rate
  );
  commit;
    EXCEPTION
    WHEN OTHERS
    THEN
      DBMS_OUTPUT.PUT_LINE(SQLERRM);
      ROLLBACK;
end CHECK_INFO_INS;

这是我的 C# 代码:

        decimal expectedCost = Decimal.Parse(ExpCostTextBox.Text);
        DateTime lastCheck = DateTime.Parse(LastCheckdateTimePicker.Text);
        DateTime nextCheck = DateTime.Parse(NextCheckdateTimePicker.Text);
        int checkType = int.Parse(ChCmbx.SelectedValue.ToString());
        string AirCraft = AirCraftCmbx.SelectedValue.ToString();
        int curID = int.Parse(CurrComboBox.SelectedValue.ToString());
        decimal curRate = decimal.Parse(CurRateTextBox.Text.Replace('.',','));


        con = new OracleConnection(conStr);
        con.Open();
        cmd = con.CreateCommand();
        cmd.BindByName = true;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = schema_name + ".CHECK_INFO_INS";

        cmd.Parameters.Add("p_id_aircraft", OracleDbType.NVarchar2, AirCraft, ParameterDirection.Input);
        cmd.Parameters.Add("p_id_check_categories", OracleDbType.Int32, checkType, ParameterDirection.Input);
        cmd.Parameters.Add("lastCheck", OracleDbType.Date, lastCheck, ParameterDirection.Input);
        cmd.Parameters.Add("nextCheck", OracleDbType.Date, nextCheck, ParameterDirection.Input);
        cmd.Parameters.Add("p_expectedcost", OracleDbType.Decimal, expectedCost, ParameterDirection.Input);
        cmd.Parameters.Add("p_id_currency", OracleDbType.Int32, curID, ParameterDirection.Input);
        cmd.Parameters.Add("p_currency_rate", OracleDbType.Decimal, curRate, ParameterDirection.Input);
        cmd.ExecuteNonQuery();

它在 executeNonQuery 行上引发异常:

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

我试图重新创建该过程,但它不起作用。我的 C# 代码有什么问题?

4

3 回答 3

2

我对 Oracle 不是很熟悉,但是您的过程中的第二个参数名为“p_id_check_type”,而当您将参数添加到参数集合时,您使用名称“p_id_check_categories”。这可能是你的问题吗?

于 2012-09-20T15:38:10.117 回答
0

:p_currency_rateOracle 参数名称在参数列表和 SQL 语句中都应以冒号开头,例如。

于 2012-09-20T11:47:59.683 回答
0

克里斯是对的,

您在调用存储过程时使用了错误的参数名称。

所以在你的电话中:

   cmd.Parameters.Add("p_id_check_categories", OracleDbType.Int32, checkType, ParameterDirection.Input);
cmd.Parameters.Add("lastCheck", OracleDbType.Date, lastCheck, ParameterDirection.Input);
        cmd.Parameters.Add("nextCheck", OracleDbType.Date, nextCheck, ParameterDirection.Input);

它应该与在存储过程中找到的参数值相同,如下所示:

    cmd.Parameters.Add("p_id_check_type", OracleDbType.Int32, checkType, ParameterDirection.Input);
cmd.Parameters.Add("p_last_check", OracleDbType.Date, lastCheck, ParameterDirection.Input);
        cmd.Parameters.Add("p_next_check", OracleDbType.Date, nextCheck, ParameterDirection.Input);

至少每当我遇到这个问题时:

PLS-00306:调用“CHECK_INFO_INS”时参数的数量或类型错误

这通常是我遇到这个问题的原因,除非我的参数顺序错误。

于 2012-09-20T18:48:21.740 回答