Trigger on a multiple tables.
KVBAug 17 2012 — edited Aug 18 2012I have an emp table(empno,ename,deptno) and dept table (deptno,dname)
I have a third table emp_details(empno,ename,deptno,dname)
I have a procedure which outputs the empdetails
I have a query in th eabove procedure select * from emp_details; which outputs all the details.
I want to write a trigger such that,
If I insert or update a row in the emp or dept table then it should get inserted/updated into emp_details table also.
I am able to write triggers ona single table.I am unable to get the rows inserted or updated when it comes to multiple tables.
Data provided:
create table emp
(empno number primary key,
ename varchar2(20),
deptno number
)
create table dept
(depno number primary key,
dname varchar2(20)
)
insert into dept values(10,'hyderabad');
insert into dept values(20,'bangalore');
insert into emp values(1,'A',10);
insert into emp values(2,'B',20);
CREATE TABLE EMP_DETAILS
AS
SELECT E.ENAME,E.EMPNO,E.DEPTNO,D.DNAME
FROM
EMP E,DEPT D
WHERE E.DEPTNO=D.DEPTNO;
CREATE OR REPLACE PROCEDURE PROC_EMP_DETAILS(P_EMPNO EMP.EMPNO%TYPE OUT ,P_ENAME EMP.ENAME%TYPE OUT,P_DEPTNO EMP.DEPTNO%TYPE OUT,P_DNAME DEPT.DNAME%TYPE OUT)
AS
/*SAMPLE CODE */
BEGIN
SELECT * FROM EMP_DETAILS;
END;
/
I tried like this
CREATE OR REPLACE TRIGGER TRIG_EMP_DETAILS
AFTER INSERT OR UPDATE ON EMP
FOR EACH ROW
REFERENCING OLD AS OLD NEW AS NEW
BEGIN
INSERT INTO EMP_DETAILS VALUES(:NEW.EMPNO,:NEW.ENAME,:NEW.DEPTNO,???????)
????-As the column we are getting fromdept table How to represent that?
Could you please guide me in this regard?
Thanks in advance
KVB