When inserting a bad record, send the error record to another table with Oracle Error
Date: Wed, 9 Jan 2008 08:44:01 -0800 (PST)
Message-ID: <b132e958-4815-4b4a-ac9b-79546ddaa517@p69g2000hsa.googlegroups.com>
Say I have a table SCOTT.EMP and when someone inserts into the table
and incurrs and error (Violated PK, FK constraints, etc) I want that
record to write to an EMPAUDIT table so I can review it. I wrote
this trigger that I thought would do the job, but it does not. My
next step would be to add a field to EMPAUDIT called ERRMSG and write
the SQLERRM to the table too. Just trying to get this to work first.
CREATE OR REPLACE TRIGGER empTrg
AFTER INSERT
ON emp
FOR EACH ROW
BEGIN
NULL;
EXCEPTION
WHEN others then
INSERT INTO empaudit(EMPNO, ENAME, JOB, MGR,HIREDATE, SAL, COMM,
DEPTNO ) VALUES
(:new.EMPNO, :new.ENAME, :new.JOB, :new.MGR,:new.HIREDATE, :new.SAL, :new.COMM, :new.DEPTNO);
END empTrg ;
/
Here is EMPAUDIT
EMPNO
ENAME
JOB
MGR
HIREDATE
SAL
COMM
DEPTNO
AUDITDATE
AUDITCODE
The trigger compiles, a PK violation shows up in SQLPLUS, but the
record does not go to EMPAUDIT with this trigger.
Received on Wed Jan 09 2008 - 10:44:01 CST