Download as DOC, PDF, TXT or read online from Scribd
Download as doc, pdf, or txt
You are on page 1of 3
CREATE TABLE CUSTOMERsal (
ID INT PRIMARY KEY,
NAME VARCHAR(10), AGE INT, ADDRESS VARCHAR(25), SALARY DECIMAL(10, 2) );
CREATE OR REPLACE TRIGGER salary_difference_triggersal
BEFORE INSERT OR UPDATE OR DELETE ON CUSTOMERsal FOR EACH ROW DECLARE old_salary NUMBER; new_salary NUMBER; BEGIN IF INSERTING OR UPDATING THEN old_salary := NVL(:OLD.SALARY, 0); new_salary := NVL(:NEW.SALARY, 0); DBMS_OUTPUT.PUT_LINE('Salary difference: ' || (new_salary - old_salary)); ELSIF DELETING THEN old_salary := NVL(:OLD.SALARY, 0); DBMS_OUTPUT.PUT_LINE('Salary before deletion: ' || old_salary); END IF; END; / INSERT INTO CUSTOMERsal (ID, NAME, AGE, ADDRESS, SALARY) VALUES (1, 'John Doe', 30, '123 Main St', 50000);
CREATE OR REPLACE TRIGGER salary_difference_triggersal
AFTER INSERT OR UPDATE OR DELETE ON customersal FOR EACH ROW DECLARE old_salary customer00.salary%TYPE; new_salary customer00.salary%TYPE; difference NUMBER; BEGIN IF INSERTING THEN DBMS_OUTPUT.PUT_LINE('New record inserted.'); DBMS_OUTPUT.PUT_LINE('ID: ' || :NEW.ID || ', Name: ' || :NEW.NAME || ', Age: ' || :NEW.AGE || ', Address: ' || :NEW.ADDRESS || ', Salary: ' || :NEW.SALARY); ELSIF UPDATING THEN old_salary := :OLD.SALARY; new_salary := :NEW.SALARY; difference := new_salary - old_salary; DBMS_OUTPUT.PUT_LINE('Salary updated for ID: ' || :NEW.ID || '. Old Salary: ' || old_salary || ', New Salary: ' || new_salary || ', Salary Difference: ' || difference); ELSIF DELETING THEN DBMS_OUTPUT.PUT_LINE('Record deleted for ID: ' || :OLD.ID || ', Name: ' || :OLD.NAME || ', Age: ' || :OLD.AGE || ', Address: ' || :OLD.ADDRESS || ', Salary: ' || :OLD.SALARY); END IF; END; /
CREATE OR REPLACE TRIGGER salary_difference_triggersal
AFTER INSERT OR UPDATE OR DELETE ON customersal FOR EACH ROW DECLARE old_salary customer00.salary%TYPE; new_salary customer00.salary%TYPE; difference NUMBER; BEGIN IF INSERTING THEN DBMS_OUTPUT.PUT_LINE('New record inserted.'); DBMS_OUTPUT.PUT_LINE('ID: ' || :NEW.ID || ', Name: ' || :NEW.NAME || ', Age: ' || :NEW.AGE || ', Address: ' || :NEW.ADDRESS || ', Salary: ' || :NEW.SALARY); ELSIF UPDATING THEN old_salary := :OLD.SALARY; new_salary := :NEW.SALARY; difference := new_salary - old_salary; DBMS_OUTPUT.PUT_LINE('Salary updated for ID: ' || :NEW.ID || '. Old Salary: ' || old_salary || ', New Salary: ' || new_salary || ', Salary Difference: ' || difference); ELSIF DELETING THEN DBMS_OUTPUT.PUT_LINE('Record deleted for ID: ' || :OLD.ID || ', Name: ' || :OLD.NAME || ', Age: ' || :OLD.AGE || ', Address: ' || :OLD.ADDRESS || ', Salary: ' || :OLD.SALARY); END IF; END; /
INSERT INTO CUSTOMERsal (ID, NAME, AGE, ADDRESS, SALARY) VALUES (2, 'John Doe', 30, '123 Main St', 60000); Update CUSTOMERsal set salary=salary+2000 where id=2;