问题
I've created a basic audit table so that if there any any changes to a 'Employee' table be they insert, update, delete, the time, the user and what the action is are stored in a 'audit employee' table.
I just wondered if it was possible so that the trigger would only fire if the changes made on the 'Employee' table were after say 5pm until 7am?
Does anyone have any ideas how this would be possible possibly using SYSDATE?
Thanks
回答1:
You cannot control whether the trigger will fire based on the time of day. You can, however, add logic to the trigger so that you only insert data into the history table between certain hours. Something like
IF( to_number( to_char(sysdate, 'hh24')) >= 17 or
to_number( to_char(sysdate, 'hh24')) < 7 )
THEN
INSERT INTO employee_history...
END IF;
来源:https://stackoverflow.com/questions/15534951/oracle-pl-sql-trigger-to-only-run-if-changes-made-to-data-after-9-5-hours