Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Update trigger, detecting missing columns
"DA Morgan" <damorgan_at_psoug.org> a écrit dans le message de news: 1135185379.283905_at_jetspin.drizzle.com...
| Michel Cadot wrote:
| > "DA Morgan" <damorgan_at_psoug.org> a écrit dans le message de news: 1135123383.641521_at_jetspin.drizzle.com...
| > |
| > | Then what's wrong with:
| > |
| > | IF :NEW.bonus IS NULL THEN
| > |
| > | or
| > |
| > | IF :NEW.bonus IS NULL and :OLD.bonus IS NOT NULL THEN
| > |
| > | I still don't see what it is you are trying to do that you don't
| > | already have the tools to handle.
| > | --
| > | Daniel A. Morgan
| > | http://www.psoug.org
| > | damorgan_at_x.washington.edu
| > | (replace x with u to respond)
| >
| > SQL> create table zz (a number primary key, b number, c number);
| >
| > Table created.
| >
| > SQL> insert into zz values(2,1000,0);
| >
| > 1 row created.
| >
| > SQL> create or replace trigger zz_bu before update on zz for each row
| > 2 begin
| > 3 dbms_output.put_line('New B='||:new.b);
| > 4 end;
| > 5 /
| >
| > Trigger created.
| >
| > SQL> update zz set c=1 where a=2;
| > New B=1000
| >
| > 1 row updated.
| >
| > When you don't set B in update, :new.B is set to its previous value.
| > The question is: how to know if B is not set or if B is set to 1000 in the update?
| >
| > Maybe to explicitly set it to NULL in the update:
| >
| > SQL> update zz set c=1, b=null where a=2;
| > New B=
| >
| > 1 row updated.
| >
| >
| > Regards
| > Michel Cadot
|
|
|
|
|
|
|
|
|
|
|
|
The issue is the following one:
- if B is given in the set clause then set B to this new value
- if B is not given is the set clause then clear B (for instance).
Now the example:
create table zz (a number primary key, b number, c number);
insert into zz values(2,1000,0);
update zz set c=1, b=1000 where a=2;
select a,b,c from zz where a=2;
--> there row must be 2,1000,1
update zz set c=1 where a=2;
select a,b,c from zz where a=2;
--> there row must be 2,0,1
I don't see how to write a trigger that can handle that as in both cases :old.B=:new.B=1000.
Regards
Michel Cadot
Received on Wed Dec 21 2005 - 12:50:48 CST