插入触发器更新后

时间:2013-05-05 14:22:37

标签: sql oracle triggers insertafter

CREATE TABLE  "EMPLOYEE_BP" 
   (    "EMP_ID" VARCHAR2(10) NOT NULL ENABLE, 
"FNAME" VARCHAR2(20), 
"LNAME" VARCHAR2(20), 
"JOB_ROLE" VARCHAR2(20), 
"AIRPORT_CODE" VARCHAR2(10) NOT NULL ENABLE, 
"SALARY" NUMBER(9,0), 
"MOBILE" NUMBER(10,0)
 );

CREATE or REPLACE TRIGGER emp_after_insert AFTER INSERT ON EMPLOYEE
FOR EACH ROW
DECLARE
BEGIN
INSERT INTO EMPLOYEE_BP values (:NEW.EMP_ID, :NEW.FNAME, :NEW.LNAME,  :NEW.JOB_ROLE, :    NEW.AIRPORT_CODE, : NEW.SALARY, : NEW.MOBILE);
DBMS_OUTPUT.PUT_LINE('Record successfully inserted into emp_backup table');
END;

--> Apparently constraints are not inserted into backup tables

该表已创建,但它为第4行的触发器提供了错误,其中begin语句为。忽略第4行语句中的错误错误。合成器似乎没问题,我确信这是一个小错误,但我无法弄明白。我正在使用Oracle。

提前致谢。

2 个答案:

答案 0 :(得分:3)

运行触发器,我实际上得到了一个内部Oracle错误,这是不好的。但我认为问题在于:NEW之间的空格。

这对我有用:

SQL> CREATE or REPLACE TRIGGER emp_after_insert AFTER INSERT ON EMPLOYEE
  2  FOR EACH ROW
  3  DECLARE
  4  BEGIN
  5  INSERT INTO EMPLOYEE_BP values (:NEW.EMP_ID, :NEW.FNAME, :NEW.LNAME,  :NEW.JOB_ROLE, :NEW.AIRPORT_CODE, :NEW.SALARY, :NEW.MOBILE);
  6  DBMS_OUTPUT.PUT_LINE('Record successfully inserted into emp_backup table');
  7  END;
  8  /

Trigger created.

答案 1 :(得分:1)

我不是Oracle专家,但您需要打击DECLARE行或实际根据此example

声明某些内容
CREATE or REPLACE TRIGGER emp_after_insert AFTER INSERT ON EMPLOYEE
FOR EACH ROW
DECLARE
    unused varchar2(10);
BEGIN
INSERT INTO EMPLOYEE_BP values (:NEW.EMP_ID, :NEW.FNAME, :NEW.LNAME,  :NEW.JOB_ROLE, :NEW.AIRPORT_CODE, :NEW.SALARY, :NEW.MOBILE);
DBMS_OUTPUT.PUT_LINE('Record successfully inserted into emp_backup table');
END;