gpt4 book ai didi

c# - ORA-06550: 调用 Oracle 存储过程时参数的数量或类型错误

转载 作者:搜寻专家 更新时间:2023-10-30 22:01:12 24 4
gpt4 key购买 nike

procedure select_card_transaction(trans_id   nvarchar2,
usr_id number,
Quantity out number) is
begin
select count(*)
into Quantity
from user_cards u
where u.transaction_id = trans_id
and u.user_id = usr_id;
end;

并使用它:

using(var conn = new OracleConnection(Settings.Default.OraWUConnString))
{
var cmd = conn.CreateCommand();
cmd.CommandText = "for_temporary_testing.select_card_transaction";
cmd.CommandType = CommandType.StoredProcedure;



cmd.Parameters.AddWithValue("trans_id", TransactionID);
cmd.Parameters.AddWithValue("usr_id", UserID);

var q = new OracleParameter("Quantity", OracleType.Number);
q.Direction = ParameterDirection.Output;
cmd.Parameters.Add(q);
//cmd.Parameters[0].OracleType = OracleType.NVarChar;
//cmd.Parameters[1].OracleType = OracleType.Number;

conn.Open();
var obj = cmd.ExecuteNonQuery();

conn.Close();
return (int)q.Value == 1;
}

它返回以下错误。ORA-06550 调用 Oracle 存储过程时参数的数量或类型错误...有什么想法吗?

最佳答案

我以前遇到过同样的问题。您使用的是 ODP.Net 驱动程序吗?我能够通过首先添加输出参数来解决问题。这需要在输入参数之前完成。在你的情况下它看起来像

 using(var conn = new OracleConnection(Settings.Default.OraWUConnString))
{
conn.Open();

var cmd = conn.CreateCommand();
cmd.CommandText = "for_temporary_testing.select_card_transaction";
cmd.CommandType = CommandType.StoredProcedure;

// Return value parameter has to be added first !
var Quantity = new OracleParameter();
Quantity.Direction = ParameterDirection.ReturnValue;
Quantity.OracleDbType = OracleDbType.Int32;
cmd.Parameters.Add(Quantity);

//now add input parameters
var TransID = cmd.Parameters.Add("trans_id", TransactionID);
TransID.Direction = ParameterDirection.Input;
TransID.OracleDbType = OracleDbType.NVarchar2;

var UsrID = cmd.Parameters.Add("usr_id", UserID);
UsrID.Direction = ParameterDirection.Input;
UsrID.OracleDbType = OracleDbType.Int32;

cmd.ExecuteNonQuery();

conn.Close();
return Convert.ToInt32(Quantity.Value);
}

关于c# - ORA-06550: 调用 Oracle 存储过程时参数的数量或类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13253000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com