我在使用c#传递数组参数时遇到问题,我的代码是:
private OracleDataAdapter da;
private OracleConnection cnn;
public DataTable select_ids_between_friends(int cod, List<int> excludeList) {
DataTable dt = new DataTable();
try
{
using (cnn = new OracleConnection(Properties.Settings.Default.connectionString1))
{
cnn.Open();
da = new OracleDataAdapter("PROC_SELECT_IDS_BT_FRIENDS", cnn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("CURSOR", OracleDbType.RefCursor, ParameterDirection.Output);
da.SelectCommand.Parameters.Add("COD_US", OracleDbType.Int32, cod, ParameterDirection.Input);
da.SelectCommand.Parameters.Add(new OracleParameter("IDS_FRIEND", OracleDbType.Int32));
da.SelectCommand.Parameters[2].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
da.SelectCommand.Parameters[2].Value = excludeList.ToArray();
da.SelectCommand.Parameters[2].Size = excludeList.Count;
da.Fill(dt);
cnn.Close();
}
}
catch (Exception ex)
{
}
return dt;
}
在数据库中我创建了数组和存储过程如下: 这是Oracle类型:
CREATE TYPE FACEBOOK.ARRAY_ID_FRIENDS AS TABLE OF INT;
最后这是我的程序:
CREATE OR REPLACE PROCEDURE PROC_SELECT_IDS_BT_FRIENDS
(DATA_CURSOR OUT SYS_REFCURSOR,COD_US IN INT, IDS_FRIEND IN FACEBOOK.ARRAY_ID_FRIENDS) IS
BEGIN
OPEN DATA_CURSOR FOR
SELECT ID_USER1,ID_USER2 FROM T_FRIENDSHIP WHERE ID_USER2 NOT IN(SELECT COLUMN_VALUE FROM TABLE(IDS_FRIEND)))
END;
/
显示的错误是PLS-00306:调用PROC_SELECT_IDS_BT_FRIENDS中的参数数量或类型错误。请帮我。提前谢谢。
答案 0 :(得分:1)
这一行:
da.SelectCommand.Parameters.Add(new OracleParameter("IDS_FRIEND", OracleDbType.Int32));
为什么它是Int32?不应该是阵列吗?我看到你将它声明为一个数组,但直到稍后。是否有不同的方式来声明它?