我在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.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#app时,我收到了这个错误:
Unhandled Exception: System.Data.OracleClient.OracleException: ORA-06550: line 1 , column 18: PLS-00306: wrong number or types of arguments in call to 'P1' ORA-06550: line 1, column 7: PL/SQL: Statement ignored
发生了什么事?
答案 0 :(得分:1)
标记为ParameterDirection.Output
的参数需要ParameterDirection.ReturnValue
而不是OUT
。
您还在使用ExecuteNonQuery
查询(SELECT
)
答案 1 :(得分:0)
在黑暗中刺伤:
// 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;