Home » SQL & PL/SQL » SQL & PL/SQL » TRIGGER on data manual change
TRIGGER on data manual change [message #19716] Thu, 04 April 2002 12:21 Go to next message
bechir
Messages: 23
Registered: November 2001
Junior Member
would any one tell me what's the problem in the attached trigger. I'm trying to update automatically the STATUS field to 'OLD' in TABLEX every time the user updates/changes the DESCRIPTION attribute of the same record.
Here is the trigger script:
/* ------------------------------------------------- */
CREATE OR REPLACE TRIGGER OWNER.TABLEX_AU_ROW
AFTER UPDATE OF DESCRIPTION ON OWNER.TABLEX
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
WHEN (NEW.DESCRIPTION != OLD.DESCRIPTION)
BEGIN
UPDATE OWNER.TABLEX SET STATUS = 'OLD' WHERE TABLEX.DESCRIPTION = :NEW.DESCRIPTION;
END;
/
/* ------------------------------------------- */
Re: TRIGGER on data manual change [message #19718 is a reply to message #19716] Thu, 04 April 2002 12:25 Go to previous messageGo to next message
Su
Messages: 154
Registered: April 2002
Senior Member
Seems to be OK. But what is the error message is it showing?
And you dont have to use REFERENCING clause if you are not chaning OLD and NEW specifiers.
Re: TRIGGER on data manual change [message #19720 is a reply to message #19716] Thu, 04 April 2002 12:59 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
1) This needs to be a before update trigger (in order to change the status value).

2) To change the value of a column on the same row, you don't use an update statement - you just assign a value using :new.column_name.

3) Also, if you description column is nullable by any chance, your WHEN condition will have to take that into account (NVL).

create or replace trigger tablex_au_row 
  before update of description on tablex 
  for each row 
  when (new.description != old.description)
begin 
  :new.status := 'OLD'; 
end;
/
Previous Topic: Calling Triggers.
Next Topic: Getting wierd error compiling package
Goto Forum:
  


Current Time: Thu Apr 25 06:59:35 CDT 2024