当我尝试使用使用两次的参数执行查询时,我得到 ORA-01008“并非所有变量都绑定”。但是,如果我将带有此参数的代码放在查询的末尾 - 它工作正常。
重现错误的简单程序
internal static class Program {
private static void Main() {
//this query does not work
ExecuteSql(@"select
category1_.ID as ID0_,
category1_.ValidUntil as ValidUntil0_
from
Invoice invoice0_,
Category category1_
where
( invoice0_.Foo<:p0 or invoice0_.Foo>:p0 )
and category1_.ValidUntil=:p1");
//this works
ExecuteSql(@"select
category1_.ID as ID0_,
category1_.ValidUntil as ValidUntil0_
from
Invoice invoice0_,
Category category1_
where
category1_.ValidUntil=:p1
and ( invoice0_.Foo<:p0 or invoice0_.Foo>:p0)");
}
private static void ExecuteSql(string commandText) {
Console.WriteLine("------");
try {
var cs = "User ID=nhibernate;Password=nhibernate;Data Source=192.168.0.101:1521";
using (var connection = new OracleConnection(cs))
using (var cmd = connection.CreateCommand()) {
cmd.BindByName = true; // I want to bind parameters by name
cmd.CommandType = CommandType.Text;
cmd.CommandText = commandText;
cmd.Parameters.Add(":p0", OracleDbType.Int32, 42, ParameterDirection.Input);
cmd.Parameters.Add(":p1", OracleDbType.TimeStamp, DateTime.Now, ParameterDirection.Input);
connection.Open();
cmd.ExecuteReader();
}
}
catch (Exception e) { Console.WriteLine(e); }
}
}
我正在使用完全托管的 ODP.NET
Db 是 Oracle XE 11g Release2