【问题标题】:Error when calling oracle procedure with c#?使用 c# 调用 oracle 过程时出错?
【发布时间】:2015-06-30 19:47:05
【问题描述】:

我在 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# 应用程序时,我得到了这个错误:

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

发生了什么?

【问题讨论】:

  • ParameterDirection.Output 不是 ParameterDirection.ReturnValue 您还使用 ExecuteNonQuery 和查询 (SELECT)
  • @AlexK。谢谢你,我的朋友,它的工作!请发布你的解决方案来投票给你的帖子。

标签: c# oracle stored-procedures


【解决方案1】:

对于标记为OUT 的参数,您需要ParameterDirection.Output 而不是ParameterDirection.ReturnValue

您还将ExecuteNonQuery 与查询(SELECT)一起使用

【讨论】:

    【解决方案2】:

    在这里暗中尝试:

    // 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;
    

    【讨论】:

      猜你喜欢
      • 2014-03-16
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 2015-09-17
      • 2016-06-05
      • 2015-12-23
      • 2015-12-12
      • 1970-01-01
      相关资源
      最近更新 更多