使用c#调用oracle过程时出错?
我在Oracle中编写了此过程:使用c#调用oracle过程时出错?,c#,oracle,stored-procedures,C#,Oracle,Stored Procedures,我在Oracle中编写了此过程: create or replace PROCEDURE P1 ( ID_1 IN NUMBER , P_NAME OUT VARCHAR2 ) AS BEGIN -- INSERT INTO A1 (ID, NAME_) VALUES (ID_1,'6666'); SELECT NAME_ into p_name FROM A1 WHERE ID=ID_1; END P1; 并用c#编写了以下代码以运行该过程: cmd.
create or replace
PROCEDURE P1
(
ID_1 IN NUMBER
, P_NAME OUT VARCHAR2
) AS
BEGIN
-- INSERT INTO A1 (ID, NAME_) VALUES (ID_1,'6666');
SELECT NAME_ into p_name FROM A1 WHERE ID=ID_1;
END P1;
并用c#编写了以下代码以运行该过程:
cmd.Connection = conn;
cmd.CommandText = "P1";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("ID_1", 88);
cmd.Parameters.Add("p_name", OracleType.VarChar, 16).Direction = ParameterDirection.ReturnValue;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
Console.WriteLine(cmd.Parameters["p_name"].Value.ToString());
cmd.Connection.Close();
但当我运行c#应用程序时,我会出现以下错误:
发生了什么事?在黑暗中摸索:
// this line looks wrong as it's not the return value, that's the return value of the procedure itself.
cmd.Parameters.Add("p_name", OracleType.VarChar, 16).Direction = ParameterDirection.ReturnValue;
// I think it should be ouput
cmd.Parameters.Add("p_name", OracleType.VarChar, 16).Direction = ParameterDirection.Output;
对于标记为
OUT
的参数,您需要ParameterDirection.Output
而不是ParameterDirection.ReturnValue
您还将
ExecuteNonQuery
用于查询(SELECT
)ParameterDirection.Output
notParameterDirection.ReturnValue
您还将ExecuteNonQuery
用于查询(SELECT
)@AlexK。谢谢你,我的朋友,这是工作!,请发布您的解决方案以投票支持您的帖子。
// this line looks wrong as it's not the return value, that's the return value of the procedure itself.
cmd.Parameters.Add("p_name", OracleType.VarChar, 16).Direction = ParameterDirection.ReturnValue;
// I think it should be ouput
cmd.Parameters.Add("p_name", OracleType.VarChar, 16).Direction = ParameterDirection.Output;