参数数量与存储过程的值数量不匹配



我使用Enterprise Library 5x DAAB来调用具有一个输入参数和一个输出参数的Oracle存储过程。但是它给出了这个错误:

参数数量与存储过程的值数量不匹配

我的代码如下:

OracleDatabase _database;
OracleConnection _connection;
...
...
DbCommand insertCommand = _database.GetStoredProcCommand("spName");
insertCommand.Connection = _connection;    
_database.AddInParameter(insertCommand, "inParam", DbType.Int16);
_database.AddOutParameter(insertCommand, "outParam", DbType.Byte, 1);
insertCommand.Prepare();
object[] paramValues = new object[] { 1, 2  };
_database.AssignParameters(insertCommand, paramValues);
_database.ExecuteNonQuery(insertCommand, _transaction);
int outParamVal = (int)_database.GetParameterValue(insertCommand, "outParam");

请注意:以上代码是完整源代码的一个小示例。但描述了类似的功能。

这是我使用的SP:

create or replace
PROCEDURE SP_APPEND_TO_PRICE_TRANSFER 
(
  FISCAL_YEAR IN NUMBER  
, FISCAL_MONTH IN NUMBER  
, PRODUCT_ID IN NUMBER
, RD_MARKUP IN NUMBER
, RD_RETAIL_PRICE IN NUMBER
, BL_MARKUP IN NUMBER
, BL_RETAIL_PRICE IN NUMBER
, RD_SPEC_FLAG IN VARCHAR2
, BL_SPEC_FLAG IN VARCHAR2
, LEMONADE_DISTRIB_PRICE IN NUMBER
, AFS_DISTRIB_PRICE IN NUMBER
, GLAZIER_DISTRIB_PRICE IN NUMBER
, GLAZIER_DISTRIB_CASE_PRICE IN NUMBER
, SARALEE1_DISTRIB_PRICE IN NUMBER
, SARALEE1_DISTRIB_CASE_PRICE IN NUMBER
, CAROLINA_DISTRIB_PRICE IN NUMBER
, NETUNITCOST IN NUMBER
, RD_INTERNAL_MARKUP IN NUMBER
, BL_INTERNAL_MARKUP IN NUMBER
, RD_TRANSFER_COST IN NUMBER
, BL_TRANSFER_COST IN NUMBER
, TOTAL_NET_WEIGHT IN NUMBER
, PRICE_TRANSFER_UOM IN VARCHAR2
, STD_PACK IN NUMBER
, PAGE_LOCATION_CODE IN VARCHAR2
, PPOD1_DISTRIB_PRICE IN NUMBER
, PPOD1_DISTRIB_CASE_PRICE IN NUMBER
, PPOD1_STOCK_FLAG IN VARCHAR2
, SLASHOUT_PRICE_RD IN NUMBER
, SLASHOUT_PRICE_BL IN NUMBER
, ROWSINSRTD OUT NUMBER
) AS 
BEGIN
  INSERT INTO PRICE_TRANSFER ( 
    FISCAL_YEAR, 
    FISCAL_MONTH, 
    PRODUCT_ID, 
    CHI_REBATE_PCT, 
    CHI_RETAIL_PRICE, 
    NE_REBATE_PCT, 
    NE_RETAIL_PRICE, 
    CHI_SPEC_FLAG, 
    NE_SPEC_FLAG, 
    LEMONADE_DISTRIB_PRICE, 
    AFS_DISTRIB_PRICE, 
    GLAZIER_DISTRIB_PRICE, 
    GLAZIER_DISTRIB_CASE_PRICE, 
    SARALEE1_DISTRIB_PRICE, 
    SARALEE1_DISTRIB_CASE_PRICE, 
    CAROLINA_DISTRIB_PRICE, 
    NETUNITCOST, 
    CHI_INTERNAL_MARKUP, 
    NE_INTERNAL_MARKUP, 
    CHI_TRANSFER_COST, 
    NE_TRANSFER_COST, 
    TOTAL_NET_WEIGHT, 
    PRICE_TRANSFER_UOM, 
    CASE_PACK_FACTOR, 
    PAGE_LOCATION_CODE, 
    PPOD1_DISTRIB_PRICE, 
    PPOD1_DISTRIB_CASE_PRICE, 
    PPOD1_STOCK_FLAG, 
    SLASHOUT_PRICE_RD, 
    SLASHOUT_PRICE_BL )
    VALUES (
    FISCAL_YEAR
, FISCAL_MONTH  
, PRODUCT_ID
, RD_MARKUP
, RD_RETAIL_PRICE
, BL_MARKUP
, BL_RETAIL_PRICE
, RD_SPEC_FLAG
, BL_SPEC_FLAG
, LEMONADE_DISTRIB_PRICE
, AFS_DISTRIB_PRICE
, GLAZIER_DISTRIB_PRICE
, GLAZIER_DISTRIB_CASE_PRICE
, SARALEE1_DISTRIB_PRICE
, SARALEE1_DISTRIB_CASE_PRICE
, CAROLINA_DISTRIB_PRICE
, NETUNITCOST
, RD_INTERNAL_MARKUP
, BL_INTERNAL_MARKUP
, RD_TRANSFER_COST
, BL_TRANSFER_COST
, TOTAL_NET_WEIGHT
, PRICE_TRANSFER_UOM
, STD_PACK
, PAGE_LOCATION_CODE
, PPOD1_DISTRIB_PRICE
, PPOD1_DISTRIB_CASE_PRICE
, PPOD1_STOCK_FLAG
, SLASHOUT_PRICE_RD
, SLASHOUT_PRICE_BL );
ROWSINSRTD := sql%rowcount;
END SP_APPEND_TO_PRICE_TRANSFER;

2011-11-02
所以,目前似乎没有解决这个问题的办法。所以暂时,我用下面的方法完成了我的工作。非常基本的东西…

...
...
OracleConnection _connection = _dbConnect.OpenOracleDB();   //custom API to get the Connection object
OracleTransaction transaction = _connection.BeginTransaction();
int affectedRows = 0;
OracleCommand insertCommand = new OracleCommand("MyProc", _connection, transaction);
using (insertCommand)
{
    insertCommand.CommandType = CommandType.StoredProcedure;
    OracleParameter param1 = new OracleParameter("PARAM1", OracleType.Number);
    param1.Direction = ParameterDirection.Input;
    insertCommand.Parameters.Add(param1);
    OracleParameter param2 = new OracleParameter("PARAM2", OracleType.Number);
    param2.Direction = ParameterDirection.Input;
    insertCommand.Parameters.Add(param2);
    OracleParameter outParam = new OracleParameter("OUTPARAM", OracleType.Int32);
    outParam.Size = 1;
    outParam.Direction = ParameterDirection.Output;
    insertCommand.Parameters.Add(outParam);                    
    insertCommand.Prepare();
    foreach (MyObject myObject in myObjects)    //myObjects is a list of objects I want to persist
    {
        param1.Value = myObject.Prop1;
        param2.Value = myObject.Prop2;
        insertCommand.ExecuteNonQuery();
        affectedRows = Convert.ToInt32(outParam.Value);
    }
    transaction.Commit();
}
...
...

根据我的计算,您的存储过程有30个输入参数和1个输出参数。如果您想让它运行,您将需要提供流程所需的所有30个输入参数。

MSDN - OracleDatabase.AssignParameters.

由此,我收集这是因为您正在传递两个(2)个参数(paramValues)的数组,并且只创建了一个(1)个类型为DbType.Int16的InParameter。

//FIRST AND ONLY IN PARAM
_database.AddInParameter(insertCommand, "inParam", DbType.Int16);
...
object[] paramValues = new object[] { 1, 2  }; //2 PARAMETER VALUES

另外,请参阅Using语句,因为任何IDisposable都应该在Using语句中。

相关内容

  • 没有找到相关文章

最新更新