Question

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

​The table gets created, but it gives me an error for the trigger on line 4,where the begin statement is. Ther error is error at line 4 statement ignored. The synthax seems ok and I'm confident it's a small error but I can't figure it out. I am using Oracle.

Thanks in advance.

Was it helpful?

Solution

Running the trigger as you have it, I actually get an internal Oracle error, which is not good. But I think the problem is with the spaces you have between the : and the NEW.

This works for me:

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.

OTHER TIPS

I'm not an Oracle expert but you would either need to strike your DECLARE line or actually declare something based on this 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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top