我想创建一个触发器
- select staffid where dateread = 本月日期
- 计算一个staffID的数量
- 如果该员工在该月的人数超过 5
- 将发出停止。
这就是我所做的让我感到困惑的事情
我想知道这在逻辑上正确吗?这是我的编译器日志错误
这是我需要的结果:抄表员在任何给定日历月最多只能读取 5 米
我的阅读表有
StaffID
MeterID
DateRead
ReadinID (PK)
这是错误文本:
Error(5,7): PL/SQL: SQL Statement ignored Error(5,27):
PL/SQL:ORA-00923: FROM keyword not found where expected
C:\Users\ChrisPin\AppData\Roaming\SQL Developer\assgn2 sat4.sql Error(5,7):
PL/SQL: SQL Statement ignored Error(5,27):
PL/SQL: ORA-00923: FROM keyword not found where expected
这是触发代码:
CREATE OR REPLACE TRIGGER LIMIT_5_REDINGS
BEFORE UPDATE OR INSERT ON reading
FOR EACH ROW
DECLARE
ReadingCount INTEGER; --# of depts for this employee
max_read INTEGER := 5; --max number of depts per employee.
BEGIN
select Reading COUNT(*) into ReadingCount
from (select *
from Reading
where to_char(DateRead, 'YYYY-MM') = to_char(sysdate, 'YYYY-MM'))
WHERE STAFFID = :NEW.STAFFID;
IF :OLD.STAFFID = :NEW.STAFFID THEN
RETURN;
ELSE
IF ReadingCount >= max_read THEN
RAISE_APPLICATION_ERROR (-20000,'Employees are limited to a max of two departments.');
END IF;
END IF;
END;