views:

548

answers:

2

I've created a trigger manually (By pasting the SQL from another oracle db into the management console) which auto increments the primary key of a table and when I look at the trigger in the object browser The trigger is listed as invalid.

Why would this be the case?

Here is the SQL that recreates the trigger:

CREATE OR REPLACE TRIGGER  "BI_AGENTEVENTDATA" 
  before insert on "AGENTEVENTDATA"               
  for each row  
begin   
    select "AGENTEVENTDATA_SEQ".nextval into :NEW.ID from dual; 
end; ;
/
ALTER TRIGGER  "BI_AGENTEVENTDATA" ENABLE
/
+1  A: 

are you sure that the sequence exists and can be used by the trigger?

Try this:

select sequence_name from user_sequences;
Oliver Michels
The sequence was missing I'd forgot to migrate it over... DOH!
Omar Kooheji
A: 

Try the trigger without the " . In other words:

CREATE OR REPLACE TRIGGER  "BI_AGENTEVENTDATA" 
  before insert on "AGENTEVENTDATA"               
  for each row  
begin   
    select AGENTEVENTDATA_SEQ.nextval into :NEW.ID from dual; 
end; ;
/
ALTER TRIGGER  "BI_AGENTEVENTDATA" ENABLE
/
Nuno Furtado