Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在c#中为返回值编写oracle插入查询?_C#_Sql_Oracle - Fatal编程技术网

如何在c#中为返回值编写oracle插入查询?

如何在c#中为返回值编写oracle插入查询?,c#,sql,oracle,C#,Sql,Oracle,我编写的查询没有返回值,如下所示: con.Open(); OracleCommand cmd= CreateCommand(); cmd.CommandText = $"INSERT INTO {"Customer".GetDoubleQuoted()}({"City".GetDoubleQuoted()},{"CompanyName".GetDoubleQuoted()} , {"ContactName".GetDoubleQuoted()} ,{"Country".GetDo

我编写的查询没有返回值,如下所示:

  con.Open();
  OracleCommand  cmd= CreateCommand();
  cmd.CommandText = $"INSERT INTO {"Customer".GetDoubleQuoted()}({"City".GetDoubleQuoted()},{"CompanyName".GetDoubleQuoted()} , {"ContactName".GetDoubleQuoted()} ,{"Country".GetDoubleQuoted()},{"CustomerID".GetDoubleQuoted()},{"Phone".GetDoubleQuoted()}) VALUES ('Chicago', 'Amisys','Jwk', 'USA','aaa', '123456') \n Returning {"City".GetDoubleQuoted()} into :city";
  cmd.Connection = con;
  cmd.Parameters.Add(new OracleParameter
  {
       ParameterName = ":city",
       OracleDbType = OracleDbType.Varchar2,
       Direction = ParameterDirection.Output
   });
   cmd.ExecuteNonQuery();
  var value= cmd.Parameters[":city"].Value.ToString();
有人能帮我找出为什么价值没有显现出来吗

提前谢谢。
joon

错误是ODP.NET中的一个小错误,每次收到
varchar2
returnValue
参数时,必须指定大小。因此,只需在示例中添加一行
Size=32000,
,它就可以工作了

请参阅下面的完整代码:

 con.Open();
 OracleCommand  cmd= CreateCommand();
 cmd.CommandText = $@"INSERT INTO {"Customer".GetDoubleQuoted()(
        {"City".GetDoubleQuoted()},
        {"CompanyName".GetDoubleQuoted()},
        {"ContactName".GetDoubleQuoted()},
        {"Country".GetDoubleQuoted()},
        {"CustomerID".GetDoubleQuoted()},
        {"Phone".GetDoubleQuoted()}
     ) VALUES ('Chicago', 'Amisys','Jwk', 'USA','aaa', '123456')
     Returning {"City".GetDoubleQuoted()} into :city";
 cmd.Connection = con;
 cmd.Parameters.Add(new OracleParameter
     {
         ParameterName = ":city",
         OracleDbType = OracleDbType.Varchar2,
         Size = 32000,
         Direction = ParameterDirection.ReturnValue
     });
 cmd.ExecuteNonQuery();
 var value= cmd.Parameters[":city"].Value.ToString();

注意:
32000
varchar2
列的最大大小。

尝试将参数方向设置为ReturnValueThank Roy,但它没有做任何更改。感谢Roy,我得到了预期的返回值。再次感谢。