SQL - Trigger is invalid and failed re-validation

时间:2016-10-20 19:23:00

标签: sql oracle triggers

When a user creates an application for the table 'application' I want a copy placed into the table 'application_history'. I've tried creating a trigger and get the error that is in the title.

create or replace TRIGGER create_history AFTER INSERT ON application
FOR EACH ROW
DECLARE
BEGIN
insert into application_history values (:new.arn, :new.srn, :new.job_id, :new.application_status);
END;

Any help will be much appreciated.

2 个答案:

答案 0 :(得分:0)

我认为你最后需要一个/。所以:

create or replace TRIGGER create_history AFTER INSERT ON application
FOR EACH ROW
DECLARE
BEGIN
insert into application_history values (:new.arn, :new.srn, :new.job_id, :new.application_status);
END;
/

答案 1 :(得分:0)

正如贾斯汀所怀疑的那样,你似乎在application_history中拥有超过4列。为所有列提供值或指定列,并插入table1(col1,col2)值(1,2)'

在添加了额外的列' hist_id'之后,它对我有用(只是为了给你一个想法)......

create table application (arn number, srn number, job_id number, application_status char(1) );

create table application_history (hist_id number, arn number, srn number, job_id number, application_status char(1) );

create or replace TRIGGER create_application_history AFTER INSERT ON application
FOR EACH ROW
DECLARE
BEGIN
  insert into application_history values (1, :new.arn, :new.srn, :new.job_id, :new.application_status);
END;
/