“ORA-01036:C# 中的 oracle clob 的非法变量名称/编号\n”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3493027/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"ORA-01036: illegal variable name/number\n" for oracle clob in C#
提问by user421719
When I try to create an oracle stored procedure call with clob
input and output in C#, I get the following error:
当我尝试clob
在 C# 中创建带有输入和输出的 oracle 存储过程调用时,出现以下错误:
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();
回答by Incognito
Just try
你试一试
command.CommandText =
@"declare xx clob;
begin dbms_lob.createtemporary(xx, false, 0);
tempclob := xx; end;";
Replace :tempclob
with tempclob
.
替换:tempclob
为tempclob
。
回答by Nicholas
Try adding:
尝试添加:
command.BindByName = true;
after you call your parameters.
在调用参数之后。
回答by Pavel Gatnar
Binding variable to an anonymous pl/sql block is not supported. Use a procedure and define all parameters instead.
不支持将变量绑定到匿名 pl/sql 块。改为使用过程并定义所有参数。
command.CommandText = "dbms_lob.createtemporary"
回答by Dave Costa
Which of the two calls to ExecuteNonQuery() is generating the error? I'm guessing it's the second one.
对 ExecuteNonQuery() 的两次调用中的哪一个会产生错误?我猜是第二个
I don't do C#, but from several examples I found online, it looks like when you are using the StoredProcedure command type, you don't want to create actual OracleParameter objects. Instead, you initialize the parameters like this:
我不使用 C#,但从我在网上找到的几个示例来看,当您使用 StoredProcedure 命令类型时,您似乎不想创建实际的 OracleParameter 对象。相反,您可以像这样初始化参数:
command.Parameters.Add("iSourceSystem", OracleType.VarChar).Value = "XXX";
回答by Threekill
It looks like you might be using the Microsoft Oracle client.
看起来您可能正在使用 Microsoft Oracle 客户端。
Try using the Oracle 11 client with ODP.Net for 4.0. This gives the best results when dealing with clob's.
尝试将 Oracle 11 客户端与 ODP.Net for 4.0 一起使用。这在处理 clob 时给出了最好的结果。