Dbms 7 Trigger
Dbms 7 Trigger
Table created.
SQL> select * from client_mstr_55;
ACCNO NAME
---------- ----------
1001 RAJU
1002 PARAG
1004 BABURAO
1005 CHAITYA
1006 SAIRAJ
1 row updated.
1 row updated.
ACCNO OP
---------- ----------
1001 update
1004 update
1 row deleted.
ACCNO OP
---------- ----------
1001 update
1004 update
1003 Delete
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------------
Table created.
Trigger created.
1 row created.
E_NO SALARY
---------- ----------
6 20000
6 70000
1 row updated.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------
3. Write a Database trigger for following requirements:
Employee salary of last three month is stored in the emp_sal table.
emp_sal(emp_no, sal1,sal2,sal3)
before inserting salary into emp_sal table, if salary of employee in any of the
last three month is greater than Rs. 50,000/- then entry of average salary along
with emp_no needs to be inserted into new table emp_new(emp_no, avg_sal).
SQL> CREATE TABLE emp_sal_55 (e_no NUMBER,sal1 NUMBER,sal2 NUMBER,sal3 NUMBER);
Table created.
LINE/COL ERROR
-------- -----------------------------------------------------------------
10/54 PLS-00049: bad bind variable 'NEW.EMP_NO'
SQL> CREATE OR REPLACE TRIGGER t4
2 BEFORE INSERT ON emp_sal_55
3 FOR EACH ROW
4 DECLARE
5 avg_salary NUMBER;
6 BEGIN
7 -- Calculate the average salary
8 avg_salary := (:NEW.sal1 + :NEW.sal2 + :NEW.sal3) / 3;
9
10 -- Check if any of the salaries is greater than 50000
11 IF :NEW.sal1 > 50000 OR :NEW.sal2 > 50000 OR :NEW.sal3 > 50000 THEN
12 -- Insert into emp_new_55 table
13 INSERT INTO emp_new_55 (e_no, avg_sal) VALUES (:NEW.e_no, avg_salary);
14 END IF;
15 END;
16 /
Trigger created.
1 row created.
1 row created.
1 row created.
1 row created.
no rows selected
1 row created.
1 row created.
E_NO AVG_SAL
---------- ----------
5 73333.3333
5 47666.6667
5 32333.3333