Oracle quot;ORA-01008: not all variables boundquot; Error w/ Parameters(Oracle“ORA-01008:并非所有变量都绑定带参数的错误)
问题描述
这是我第一次与 Oracle 打交道,我很难理解为什么会收到此错误.
This is the first time I've dealt with Oracle, and I'm having a hard time understanding why I'm receiving this error.
我在查询的 where 子句中使用带有 C# 的 Oracle 的 ODT.NET 和以下代码:
I'm using Oracle's ODT.NET w/ C# with the following code in a query's where clause:
WHERE table.Variable1 = :VarA
AND (:VarB IS NULL OR table.Variable2 LIKE '%' || :VarB || '%')
AND (:VarC IS NULL OR table.Variable3 LIKE :VarC || '%')
我正在添加参数值,如下所示:
and I'm adding the parameter values like so:
cmd.Parameters.Add("VarA", "24");
cmd.Parameters.Add("VarB", "test");
cmd.Parameters.Add("VarC", "1234");
当我运行这个查询时,服务器返回:
When I run this query, the server returns:
ORA-01008: not all variables bound
如果我注释掉任何一个AND(...."行,查询就会成功完成.
If I comment out either of the 'AND (....' lines, the query completes successfully.
如果我只用两个参数查询,而不用三个参数查询,为什么查询会正常运行?我收到的错误甚至没有意义
Why would the query run through alright if I'm only querying with two parameters, but not with three? The error I'm receiving doesn't even make sense
推荐答案
oracle 的 ODP.Net 提供程序默认使用按位置绑定.将行为更改为按名称绑定.将属性 BindByName 设置为 true.比你可以忽略参数的双重定义.
The ODP.Net provider from oracle uses bind by position as default. To change the behavior to bind by name. Set property BindByName to true. Than you can dismiss the double definition of parameters.
using(OracleCommand cmd = con.CreateCommand()) {
...
cmd.BindByName = true;
...
}
这篇关于Oracle“ORA-01008:并非所有变量都绑定"带参数的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Oracle“ORA-01008:并非所有变量都绑定"带参数的错误
基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
