problem related to trigger [message #558351] |
Thu, 21 June 2012 03:33  |
 |
neetesh87
Messages: 280 Registered: September 2011 Location: bhopal
|
Senior Member |
|
|
hello experts,
i want to know the logic behind 'of' clause in trigger when we need to create a trigger before dml effect on particular column
of our table .
if we include all three dml operation then we know about 'delete', it delete a row not a particular column , by 'delete statement'.
so it is right with delete. and no problem with update also, but in 'insert statement' we can put null in non pk column or may be we did not include these columns in our 'insert statement' , then null will be inserted.
now we create a trigger with 'of' clause , script is like.......
create or replace trigger trg_check_sal before insert or update of sal on emp for each row
begin
if inserting then
raise_application_error(-20101,'can not perform insertion');
elsif updating then
raise_application_error(-20101,'can not perform updation');
end if;
end;
/
and i perform these statements---
insert into emp(empno,sal)values(121,1000);
then oracle gives an error--
ORA-20101: can not perform insertion
ORA-06512: at "SCOTT.TRG_CHECK_SAL", line 3
ORA-04088: error during execution of trigger 'SCOTT.TRG_CHECK_SAL'
i know this is because of trigger, but
when i fired another statement..
insert into emp(empno)values(121);
then oracle also giver error, because of trigger.
ORA-20101: can not perform insertion
ORA-06512: at "SCOTT.TRG_CHECK_SAL", line 3
ORA-04088: error during execution of trigger 'SCOTT.TRG_CHECK_SAL'
i could not understand that i am not inserting values in 'sal' column, then why trigger is fired. please explain me.
thanx in advance.....
|
|
|
|
|
|
|
|