0

I'm using pl\sql developer and I have a report table with a number(38) ID column.

I want to keep track of all updates for this table so I created another table like this:

 CREATE TABLE reportUpdate (report_id number(38), updatedate number(32));

And I created a trigger:

CREATE or REPLACE TRIGGER BeforeUpdateReport 
BEFORE 
UPDATE ON REPORT 
FOR EACH ROW 
Begin 
   INSERT INTO reportUpdate 
   Values(old.ID,sysdate); 
END;

And when I run it, I get an error, saying: trigger 'SYSTEM.BEFOREUPDATEREPORT' is invalidand failed re-validation.

Can someone please help

5
  • 1
    You most probably got a trigger created with warning when you created the trigger. Do a show errors and you'll see what is wrong with the code Commented May 9, 2014 at 9:33
  • Tags belong in the tags, not in the title. Commented May 9, 2014 at 9:37
  • Where do u see tags in the title? Commented May 9, 2014 at 9:39
  • 1
    @Shmuli: Before the edit, you had "(Oracle)" in the title. The consensus on StackOverflow is, that tags shouldn't go in the title, but in the tags field. Commented May 9, 2014 at 9:46
  • 1
    You might need to change CREATE TABLE reportUpdate (report_id number(38), updatedate date); But not so sure. Commented May 9, 2014 at 9:57

1 Answer 1

1

You can use show errors after you see compiled with warnings, or query the user_errors view to see what is wrong later.

One obvious thing is that you haven't prefixed the old reference with a colon:

CREATE or REPLACE TRIGGER BeforeUpdateReport 
BEFORE 
UPDATE ON REPORT 
FOR EACH ROW 
Begin 
   INSERT INTO reportUpdate 
   Values(:old.ID,sysdate); 
END;
/

It's also better to specify the target table fields in the insert statement:

   INSERT INTO reportUpdate (report_id, updatedate)
   Values(:old.ID,sysdate); 

But you have update_date defined in your table creation script as number(32), which doesn't make sense. As @realspirituals pointed out, it should be:

CREATE TABLE reportUpdate (report_id number, updatedate date);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.