0
這是我第一次使用SQL * Plus中的觸發器,並且我不想超過電影院顯示空間的最大容量。爲什麼我得到一個警告:觸發器編譯錯誤創建?
放映時間給出max_occupancy。這是我有:
CREATE OR REPLACE TRIGGER over_capacity
BEFORE INSERT OR UPDATE ON tickets
FOR EACH ROW
WHEN (NEW.SHOWID=OLD.SHOWID)
DECLARE
nope EXCEPTION;
ti SYS_REFCURSOR;
sh SYS_REFCURSOR;
total INT;
max_oc INT;
BEGIN
OPEN sh FOR
SELECT s.max_occupancy FROM showtimes s WHERE NEW.showid=s.showid;
FETCH sh INTO max_oc;
OPEN ti FOR
SELECT COUNT(t.userid) FROM tickets t WHERE t.showid=NEW.showid;
FETCH ti INTO total;
IF total=max_oc THEN
RAISE nope;
END IF;
EXCEPTION
WHEN nope THEN
raise_application_error (-20500, 'AT CAPACITY');
END;
/