Reputation:
I am trying to create a trigger on my database, using SQL, such that after an insert into the table HISTORY
table, if, the attribute FINISHED="T"
, the MESSAGE
attribute is "FINISHED"
else, if FINISHED="F"
, the MESSAGE
is "NOT FINISHED"
.
This is my code currently when I try to run this, it says
"Trigger created with compilation errors"
Could someone please tell me what is wrong with this statement? Thank you!
CREATE OR REPLACE TRIGGER MESSAGE_TR
AFTER INSERT
ON HISTORY
FOR EACH ROW
BEGIN
IF (HISTORY.FINISHED="T")
THEN
INSERT INTO HISTORY(MESSAGE) VALUES("FINISHED");
ELSEIF (HISTORY.FINISHED="F")
INSERT INTO HISTORY(MESSAGE)VALUES("NOT FINISHED");
END;
/
Upvotes: 0
Views: 54
Reputation: 1270873
I think this is what you intend:
CREATE OR REPLACE TRIGGER MESSAGE_TR
BEFORE INSERT
ON HISTORY
FOR EACH ROW
BEGIN
:NEW.MESSAGE := (CASE WHEN :NEW.FINISHED = 'T' THEN 'FINISHED' ELSE 'NOT FINISHED' END);
END;
Note that this is a before insert trigger, because it intends to modify the row being inserted.
Upvotes: 2