我想通過使用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