Oracle PL/SQL Trigger to only run if changes made to data after 9-5 hours

a 夏天 提交于 2020-01-05 09:12:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!