I have a number of automatically generated data access classes to handle things like inserts & updates.
These look like:
cmd.CommandType = CommandType.Text
cmd.CommandText = "UPDATE myTable set f1 = :f1, f2 = :f2, f3 = :f3 where id = :id"
cmd.Parameters.AddWithValue("开发者_JS百科:f1", _f1)
cmd.Parameters.AddWithValue(":f2", _f2)
cmd.Parameters.AddWithValue(":f3", _f3)
cmd.ExecuteNonQuery()
If I were to re-write the sql to do what I want, it would look something like
cmd.CommandText = "UPDATE myTable set f1 = pkg.getMyValue, f2 = :f2, f3 = :f3 where id = :id"
Is there any way to do this by setting _f1 to a "special" value, without changing the update SQL or the way the parameters are set? Only in certain cases will I need to set the value of f1 - most of the time, it will be null.
Using .net 2.0, and system.data.oracleclient against oracle 11.
No, you can't. A bind variable is a literal, you can't specify a package to be executed.
You might consider a trigger on the underlying table that fills f1 with pkg.getMyValue if it is null:
create or replace trigger myTrigger
before insert or update on myTable for each row
begin
if :new.f1 is null
then
:new.f1 := pkg.getMyValue;
end if;
end;
/
精彩评论