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:并非所有变量都绑定"带参数的错误


基础教程推荐
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01