在oracle 12C数据库中创建了一个包,并使用C#代码来调用它。得到错误"错误的参数数量或类型"当executeNoQuery如下所示。检查包签名并与C#中的代码进行比较。无法弄清楚这个问题。唯一不确定的类型是映射Oracle编号(10)。试图用OracleDbType.varchar2,int32,int64和Long映射它,但得到了所有相同的错误。下面是包签名和C#代码。我想知道我做了什么有什么不对,有人可以提供帮助。
包装:
create or replace PACKAGE GETIMPOSITION AS
TYPE impTyp IS TABLE OF varchar2(200);
TYPE impNm IS TABLE OF varchar2(255);
TYPE impTax IS TABLE OF char(1);
TYPE impIncld IS TABLE OF char(1);
TYPE impId IS TABLE OF varchar2(8);
TYPE impSkuId IS TABLE OF number(10,0);
TYPE impPmCd IS TABLE OF varchar2(15);
/* Get data from each OUT parameter */
procedure RMS_GET_IMPOSITION_INFO (
O_IMPOSITIONTYPES OUT impTyp,
O_ERRORDES OUT VARCHAR2,
O_ERRORCODE OUT VARCHAR2
);
END GETIMPOSITION;
C#代码:
int[] aRraybindingSize = new int[2000];
List<string> empty = new List<string>();
for (int i = 0; i < arrBindingSize.Length; i++)
{
empty.Add(string.Empty);
}
using (OracleConnection database = new OracleConnection(connString))
{
OracleCommand dbCommand = database.CreateCommand();
dbCommand.CommandType = System.Data.CommandType.StoredProcedure;
dbCommand.CommandText = ConfigurationManager.AppSettings.Get("StoredProcedureNameIMPSEX");
OracleParameter[] oracleParam = new OracleParameter[3];
oracleParam[0] = new OracleParameter("O_IMPOSITIONTYPES", OracleDbType.Varchar2, 100);
oracleParam[0].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[0].Direction = ParameterDirection.Output;
oracleParam[0].Size = empty.Count;
oracleParam[0].ArrayBindSize = arrBindingSize;
for (int i = 0; i < arrBindingSize.Length; i++)
{
oracleParam[0].ArrayBindSize[i] = 100;
}
oracleParam[0].Value = empty.ToArray();
dbCommand.Parameters.Add(oracleParam[0]);
oracleParam [1] =新的OracleParameter(&#34; O_ERRORDES&#34;,OracleDbType.Varchar2,512); oracleParam [1] .Direction = System.Data.ParameterDirection.Output;
oracleParam[2] = new OracleParameter("O_ERRORCODE", OracleDbType.Varchar2, 512);
oracleParam[2].Direction = System.Data.ParameterDirection.Output;
dbCommand.Parameters.AddRange(oracleParam);
database.Open();
int status = dbCommand.ExecuteNonQuery();
}
更改过程只有一个OUTPUT数组(如上所示)但仍然有相同的错误。如果将其更改为不是数组,则过程和C#代码从数据库调用中获取正确的数据。对于我来说,在C#代码谈话过程中,他们并不了解PLSQLAssociativeArray是什么。添加状态作为返回参数不是问题。这不是oracle函数调用。没有返回值的executeNonQuery很好,所以行int状态可以消失。对PLSQLAssociativeArray有何评论?是任何错误。还是程序需要改变?
答案 0 :(得分:0)
首先尝试添加状态参数
create or replace PACKAGE GETIMPOSITION AS
TYPE impTyp IS TABLE OF varchar2(200);
TYPE impNm IS TABLE OF varchar2(255);
TYPE impTax IS TABLE OF char(1);
TYPE impIncld IS TABLE OF char(1);
TYPE impId IS TABLE OF varchar2(8);
TYPE impSkuId IS TABLE OF number(10,0);
TYPE impPmCd IS TABLE OF varchar2(15);
/* Get data from each OUT parameter */
procedure RMS_GET_IMPOSITION_INFO (
O_IMPOSITIONTYPES OUT impTyp,
O_IMPOSITIONNAME OUT impNm,
O_IMPSTTAXABILITIES OUT impTax,
O_INCLUDEDINTAXES OUT impIncld,
O_IMPOSITIONID OUT impId,
O_IMPSTSKUS OUT impSkuId,
O_IMPSTPIMS OUT impPmCd,
O_ERRORDES OUT VARCHAR2,
O_ERRORCODE OUT VARCHAR2
);
END GETIMPOSITION;
int[] aRraybindingSize = new int[2000];
using (OracleConnection database = new OracleConnection(connString))
{
OracleCommand dbCommand = database.CreateCommand();
dbCommand.CommandType = System.Data.CommandType.StoredProcedure;
dbCommand.CommandText = ConfigurationManager.AppSettings.Get("StoredProcedureNameIMPSEX");
// Return value parameter has to be added first !
int status = new OracleParameter();
status.Direction = ParameterDirection.ReturnValue;
status.OracleDbType = OracleDbType.Int32;
cmd.Parameters.Add(status);
OracleParameter[] oracleParam = new OracleParameter[9];
oracleParam[0] = new OracleParameter("O_IMPOSITIONTYPES", OracleDbType.Varchar2, 100);
oracleParam[0].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[0].Direction = ParameterDirection.Output;
oracleParam[0].ArrayBindSize = aRraybindingSize;
oracleParam[1] = new OracleParameter("O_IMPOSITIONNAME", OracleDbType.Varchar2, 255);
oracleParam[1].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[1].Direction = ParameterDirection.Output;
oracleParam[1].ArrayBindSize = aRraybindingSize;
oracleParam[2] = new OracleParameter("O_IMPSTTAXABILITIES", OracleDbType.Char, 1);
oracleParam[2].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[2].Direction = ParameterDirection.Output;
oracleParam[2].ArrayBindSize = aRraybindingSize;
oracleParam[3] = new OracleParameter("O_INCLUDEDINTAXES", OracleDbType.Char, 1);
oracleParam[3].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[3].Direction = ParameterDirection.Output;
oracleParam[3].ArrayBindSize = aRraybindingSize;
oracleParam[4] = new OracleParameter("O_IMPOSITIONID", OracleDbType.Varchar2, 8);
oracleParam[4].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[4].Direction = ParameterDirection.Output;
oracleParam[4].ArrayBindSize = aRraybindingSize;
oracleParam[5] = new OracleParameter("O_IMPSTSKUS", OracleDbType.Int64);
oracleParam[5].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[5].Direction = ParameterDirection.Output;
oracleParam[5].Precision = 10;
oracleParam[5].Scale = 0;
oracleParam[5].Size = 10;
oracleParam[5].ArrayBindSize = aRraybindingSize;
oracleParam[6] = new OracleParameter(`enter code here`"O_IMPSTPIMS", OracleDbType.Varchar2, 15);
oracleParam[6].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oracleParam[6].Direction = ParameterDirection.Output;
oracleParam[6].ArrayBindSize = aRraybindingSize;
oracleParam[7] = new OracleParameter("O_ERRORDES", OracleDbType.Varchar2, 512);
oracleParam[7].Direction = System.Data.ParameterDirection.Output;
oracleParam[8] = new OracleParameter("O_ERRORCODE", OracleDbType.Varchar2, 512);
oracleParam[8].Direction = System.Data.ParameterDirection.Output;
dbCommand.Parameters.AddRange(oracleParam);
database.Open();
Convert.ToInt32(status.Value) = dbCommand.ExecuteNonQuery();
}