JOBS (id_job, startdate, enddate, hours_job_per_employee)
EMPLOYEE (id_employe, id_job, startdate, enddate)
例如:
JOB:
id_job startdate enddate hours_job_per_employee
------------------------------------------------------------------
1 02/05/2012 04/08/2013 1221
2 04/07/2014 12/12/2016 1825
EMPLOYEE:
id_employee id_job startdate enddate
------------------------------------------------------------------
1 1 02/05/2012 06/06/2012
1 1 01/01/2013 02/05/2013
2 1 02/08/2014 04/09/2014
1 2 03/09/2014 04/04/2015
如果每位员工每周工作时间不超过70岁,我必须用触发器检查。每位员工可以在EMPLOYEE上多次出现相同的工作。
我正在使用oracle
我尝试了这个但不起作用:
CREATE TRIGGER TRIG1
BEFORE INSERT OR UPDATE on employee
FOR EACH ROW
DECLARE
count NUMBER;
firstdate DATE;
days NUMBER;
hoursday NUMBER;
BEGIN
SELECT startdate INTO firstdate FROM employee WHERE rownum=1 AND id_employee= :NEW.id_employee ORDER BY startdate;
SELECT to_number(to_char(enddate,'J')-to_char(firstdate,'J')) INTO days FROM employee WHERE rownum=1 AND id_employee= :NEW.id_employee ORDER BY startdate DESC;
AND m.enddate > n.enddate;
FOR i IN 0..days LOOP
count:=0;
FOR j IN 0..6 LOOP
hoursday:=0;
SELECT sum(p.hours_job_per_employee//7*to_number(to_char(enddate,'J')-to_char(startdate,'J')))) INTO hoursday FROM
job p JOIN employee m ON (p.id_job=m.id_job)
WHERE :NEW.id_employee= m.id_employee AND to_char(firstdate,'J')+1 > to_char(m.startdate,'J') AND to_char(firstdate,'J')+1 < to_char(m.enddate,'J')
ORDER BY m.startdate;
firstdate := to_date(firstdate+1,'DD-MM-YY');
count := count+hoursday;
END LOOP;
IF count>70 THEN RAISE_APPLICATION_ERROR(-20000,'FAIL'); END IF;
END LOOP;
END TRIG1;
/
但是没有正确运行..为什么?不应该给它时发送我的错误