SQL Trigger Statement will create but will not run

时间:2015-05-11 14:57:56

标签: sql oracle triggers

---create EMPLOYEE table---
CREATE TABLE EMPLOYEES
(
EMPLOYEEID INT NOT NULL,
EMPLOYNAME VARCHAR2(25) NULL,
EMPLOYAGE INT NULL,
EMPLOYADDRESS VARCHAR2(25) NULL,
SALARY NUMBER(9,2) DEFAULT (0) NULL,
CONSTRAINT EMPLOYEES_PK PRIMARY KEY(EMPLOYEEID)
);

--INSERT EMPLOYEES--
INSERT INTO EMPLOYEES
VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000.00);
INSERT INTO EMPLOYEES 
VALUES (2, 'Khilan', 25, 'Delhi', 1500.00);
INSERT INTO EMPLOYEES 
 VALUES (3, 'Kaushik', 24, 'Kota', 2000.00);
INSERT INTO EMPLOYEES 
 VALUES (4,'Chaitali', 25, 'Mumbai', 6500.00);
INSERT INTO EMPLOYEES 
VALUES (5, 'Hardik', 27, 'Bhopal', 8500.00);
INSERT INTO EMPLOYEES 
VALUES (6, 'Komal', 22, 'MP', 4500.00);


--CREATE TRIGGER FOR AN UPDATE TO THE SALARY--
CREATE OR REPLACE TRIGGER display
BEFORE DELETE OR INSERT OR UPDATE ON EMPLOYEES
FOR EACH ROW
WHEN (NEW.employeeid >0)
DECLARE
sal_diff number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff);
End;


--triggering trigger with insert--
INSERT INTO EMPLOYEES (EMPLOYEEID,EMPLOYNAME,EMPLOYAGE, EMPLOYADDRESS,    SALARY)
VALUES(9,'Kri', 67, 'PK', 7900.00);

UPDATE EMPLOYEES
SET SALARY = SALARY +500
WHERE EMPLOYEEID = 4;

this code will all compile in SQL developer but when I try to update and run any of the code it will not run. I enable it through the trigger tab in developer, so it should be working fine. Any help is appreciated because I am teaching this to my self.

thanks RMan2015

0 个答案:

没有答案