9

When I try to create an oracle stored procedure call with clob input and output in C#, I get the following error:

ORA-01036: illegal variable name/number\n

Here's the code itself:

OracleTransaction transaction = connection.BeginTransaction();
OracleCommand command = connection.CreateCommand();
command.Transaction = transaction;
command.CommandText = 
      @"declare xx clob; 
      begin dbms_lob.createtemporary(xx, false, 0); 
      :tempclob := xx; end;";

command.Parameters.Add(new OracleParameter("tempclob", OracleType.Clob))
    .Direction = ParameterDirection.Output;

command.ExecuteNonQuery();

OracleLob tempLob = (OracleLob)command.Parameters[0].Value;
//byte[] tempbuff = new byte[10000];
byte[] tempbuff = System.Text.Encoding.Unicode.GetBytes(generateXMLMessage());

tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
tempLob.Write(tempbuff, 0, tempbuff.Length);
tempLob.EndBatch();
command.Parameters.Clear();
command.CommandText = "InsertMessageAndGetResponseWRP";
command.CommandType = CommandType.StoredProcedure;
//command.Parameters
//.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
command.Parameters.Add(new OracleParameter("iSourceSystem", OracleType.VarChar))
       .Value = "XXX";

command.Parameters.Add(new OracleParameter("iMessage", OracleType.Clob))
       .Value = tempLob;


command.Parameters.Add(new OracleParameter("iResponseMessage", OracleType.Clob)).Direction = ParameterDirection.Output;
command.Parameters.Add(new OracleParameter("retVar ", OracleType.Int32)).Direction = ParameterDirection.Output;

command.ExecuteNonQuery();
transaction.Commit();
4

5 回答 5

1

试试看嘛

command.CommandText = 
      @"declare xx clob; 
      begin dbms_lob.createtemporary(xx, false, 0); 
      tempclob := xx; end;";

替换:tempclobtempclob

于 2010-08-16T12:34:36.463 回答
1

尝试添加:

command.BindByName = true;

在你调用你的参数之后。

于 2013-08-12T10:05:49.580 回答
0

对 ExecuteNonQuery() 的两个调用中的哪一个产生了错误?我猜是第二个

我不使用 C#,但是从我在网上找到的几个示例中,看起来当您使用 StoredProcedure 命令类型时,您不想创建实际的 OracleParameter 对象。相反,您像这样初始化参数:

command.Parameters.Add("iSourceSystem", OracleType.VarChar).Value = "XXX";
于 2010-08-16T13:02:03.707 回答
0

看起来您可能正在使用 Microsoft Oracle 客户端。

尝试使用带有 ODP.Net 4.0 的 Oracle 11 客户端。这在处理 clob 时给出了最好的结果。

于 2013-02-07T21:56:06.490 回答
0

不支持将变量绑定到匿名 pl/sql 块。改为使用过程并定义所有参数。

command.CommandText = "dbms_lob.createtemporary"
于 2015-10-20T18:59:15.577 回答