CREATE OR REPLACE TRIGGER Guest_Change_In_WorkingHour
BEFORE INSERT OR UPDATE OR DELETE ON guest
BEGIN
IF TO_NUMBER(TO_CHAR(SYSDATE,'hh24')) < 8 -- cant do anything before 8:00am
OR TO_NUMBER(TO_CHAR(SYSDATE,'hh24')) >= 5
-- changes must be made BEFORE 5:00pm
OR TO_CHAR(SYSDATE,'dy') in ('sun','sat') THEN -- nothing on weekends
RAISE_APPLICATION_ERROR (-20000, 'Satff changes only allowed during business hours.');
END IF;
END;
/
此触发器在工作时间(上午 8 点到下午 5 点)可以执行插入、删除和更新数据。对于我的问题是,当时间是凌晨 4 点时,仍然可以插入、删除和更新数据。我发现这个触发器忽略了 AM 和 PM。怎么解决?