-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12.sql
36 lines (30 loc) · 1.16 KB
/
12.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
SET SERVEROUTPUT ON;
CREATE TABLE EMP1(EMPID NUMBER(4),EMPNAME VARCHAR2(30),SALARY NUMBER(10,2));
INSERT INTO EMP1 (EMPID, EMPNAME, SALARY) VALUES (101, 'SUSAN KURIAN', 55000.00);
INSERT INTO EMP1 (EMPID, EMPNAME, SALARY) VALUES (102, 'MILA K', 60000.00);
INSERT INTO EMP1 (EMPID, EMPNAME, SALARY) VALUES (103, 'RAGHAV V', 45000.50);
INSERT INTO EMP1 (EMPID, EMPNAME, SALARY) VALUES (104, 'DIARA LISS', 75000.75);
INSERT INTO EMP1 (EMPID, EMPNAME, SALARY) VALUES (105, 'SHEETAL SINU', 70000.00);
CREATE TABLE INCR(EMPID NUMBER(4), INCR NUMBER(10,2));
CREATE OR REPLACE TRIGGER INCR
AFTER UPDATE ON EMP1
FOR EACH ROW
BEGIN
DECLARE
INCREMENT NUMBER(10,2);
BEGIN
INCREMENT := :NEW.SALARY - :OLD.SALARY;
IF INCREMENT > 1000 THEN
INSERT INTO INCR(EMPID, INCR) VALUES(:NEW.EMPID, INCREMENT);
END IF;
END;
END;
/
UPDATE EMP1 SET SALARY=57000.00 WHERE EMPID = 101;
UPDATE EMP1 SET SALARY=50000.00 WHERE EMPID = 103;
UPDATE EMP1 SET SALARY=80000.00 WHERE EMPID = 102;
UPDATE EMP1 SET SALARY=70500.00 WHERE EMPID = 105;
SELECT * FROM EMP1;
SELECT * FROM INCR;
DROP TABLE EMP1;
DROP TABLE INCR;