我想通过使用ODP.NET从一个C#应用程序中插入数据在Oracle表中,但我得到一个ORA-01400不能插入空值错误的列,其中我不插入空值。ORA-01400不能插入空值...但我不插入空值!
这是我尝试执行的参数化SQL命令的精简版本。它被包裹在一个OracleCommand
并用的ExecuteNonQuery
一个invokation执行:
declare c int;
begin
select count(*) into c from "Entradas" where "Id" = :Id and nvl("AppId", 0) = nvl(:AppId, 0);
if c>0 then
update "Entradas" set
/*...a bunch of columns...*/,
"VisitaLaboral" = :VisitaLaboral,
/*...some more columns...*/
where "Id" = :Id and nvl("AppId",0) = nvl(:AppId, 0);
else
insert into "Entradas" (
/*... a bunch of columns...*/,
"VisitaLaboral",
/*...some more columns...*/
) values (
/*...a bunch of values...*/,
:VisitaLaboral,
/*...some more values...*/
);
end if;
end;
该行不先前所以它是命令的insert
部分所执行的一个存在。当然,我已经验证过,所有列名称和列值参数都已正确放置在SQL文本中。
问题出在VisitaLaboral
列。它的类型是NUMBER(1,0),它不接受空值,和我试图插入值0。这是怎么样的相关OracleParameter
立即命令执行之前的Visual Studio显示:
但是,如果我直接在Application Express中执行命令(直接在命令文本中提供值),它将正常工作,并插入该行。
那么,这里发生了什么? ODP.NET库中是否存在错误,或者我做错了什么?
其他信息:
- 数据库是Oracle 10g快捷版10.2.0.1.0
- Oracle.DataAccess.dll版本是4.112.1.2
- 使用Visual Studio 2010中,针对.NET框架4.0
预先感谢您!
更新:如果我使用的,而不是ODP.NET的(不建议使用)System.Data.OracleClient
类
,一切工作正常。
WTF,Oracle?不,真的,WTF?
我不知道,但也许[这个问题](http://stackoverflow.com/questions/4863960/could-somebody-explain-what- merge-statement-really-in-oracle)可能会让你感兴趣。 – Benoit 2011-03-16 09:47:02
你可以发布.net代码吗? – Harrison 2011-03-16 12:00:11
是否在ODP中尝试了“command.bindbyname = True”(默认情况下System.Data.OracleClient按名称绑定,而默认情况下按位置绑定ODP)。试试bindbyname = true,看看会发生什么 – Harrison 2011-03-16 12:52:34