You Asked
Hi,
I have one requirement on trigger.
On EMP TABLE it has column Status.
If any insert happens then status has to update 1 ,
If any updates done the status 2.
We have to write in one Trigger.
Could you please write a trigger to that requirement.
Thanks in advance.
and Connor said...
SQL> create table t ( c1 int, status int );
Table created.
SQL> create or replace
2 trigger TRG
3 before insert or update on T
4 for each row
5 begin
6 if inserting then :new.status := 1; end if;
7 if updating then :new.status := 2; end if;
8 end;
9 /
Trigger created.
SQL> insert into t (c1) values (10);
1 row created.
SQL> select * from t;
C1 STATUS
---------- ----------
10 1
SQL> update t set c1 = 20;
1 row updated.
SQL> select * from t;
C1 STATUS
---------- ----------
20 2
You might want to consider that there is also an operation called a MERGE command :-)
Is this answer out of date? If it is, please let us know via a Comment