根据计划中设定的限制,有以下触发器来查找每月允许的最大租金。代码编译,但我错过了支票。有人可以帮忙吗?
CREATE OR REPLACE TRIGGER max_dvd_count
BEFORE UPDATE OR INSERT
ON RENTAL
FOR EACH ROW
DECLARE
member_limit NUMBER(2);
BEGIN
SELECT COUNT(RENTAL.MEMBERID) INTO member_limit
FROM MEMBER, MEMBERSHIP, RENTAL
WHERE MEMBERSHIP.MEMBERSHIPID = MEMBER.MEMBERSHIPID
AND MEMBER.MEMBERID = RENTAL.MEMBERID;
raise_application_error (-20000, 'You have exceeded monthly rental limit');
END;
答案 0 :(得分:0)
假设plan1 / plan2在字段plan_name
中。您需要group by
列plan_name
并获得如下计数。另请注意,我已更改您的查询,以使用显式连接语法而不是旧式隐式连接语法。
SELECT COUNT(RENTAL.MEMBERID) INTO member_limit
FROM MEMBER
JOIN MEMBERSHIP ON MEMBERSHIP.MEMBERSHIPID = MEMBER.MEMBERSHIPID
JOIN RENTAL ON MEMBER.MEMBERID = RENTAL.MEMBERID
GROUP BY plan_name;
现在,您可以使用IF
条件轻松检查条件,例如
IF(member_limit > 4) THEN
raise_application_error (-20000, 'You have exceeded monthly rental limit for Plan1');
ELSE
raise_application_error (-20000, 'You have exceeded monthly rental limit for Plan2');
END IF;