Oracle数据库TRIGGER在某些情况下不起作用

发布于 2025-01-14 11:52:38 字数 469 浏览 3 评论 0原文

Oracle 数据库有一个包含多个列的表,其中 1 个列名为 DATEMODIFIED。 当我通过脚本更新表时:

UPDATE TABLE1
  SET AMOUNT = 10
WHERE ID IN (3,4,5,6,7); 
COMMIT; 

然后,名为 DATEMODIFIED 的日期列将自动更新。 我可以找到触发代码如下:

CREATE OR REPLACE TRIGGER SET_TABLE1_DATEMODIFIED
  BEFORE UPDATE ON TABLE1 FOR EACH ROW
BEGIN
  :NEW.DATEMODIFIED := SYSDATE;
END;

但是,我可以找到 AMOUNT 值已更新的多个实例,而不会触发 DATEMODIFIED 中的更改。 Oracle系统如何实现这样的改变呢?是否有查询可以修改数据库值而不考虑 TRIGGER 语句?

The Oracle database has a table with multiple columns, with 1 column named DATEMODIFIED.
When I update the table via script:

UPDATE TABLE1
  SET AMOUNT = 10
WHERE ID IN (3,4,5,6,7); 
COMMIT; 

Then the date is column named DATEMODIFIED would be updated automatically.
I can find the trigger code as follows:

CREATE OR REPLACE TRIGGER SET_TABLE1_DATEMODIFIED
  BEFORE UPDATE ON TABLE1 FOR EACH ROW
BEGIN
  :NEW.DATEMODIFIED := SYSDATE;
END;

However, I can find multiple instances that the AMOUNT value was update, without triggering a change in DATEMODIFIED. How can the Oracle system achieve such change? Are there anyway query can amend database values disregarding TRIGGER statements?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

涙—继续流 2025-01-21 11:52:38

最有可能的是以下选项之一

  • 更新行时触发器不存在
  • 更新行时禁用触发器
  • 某些其他 SQL 语句将 lastModified 设置为 null

当然,也有可能您没有准确识别金额更新的情况。例如,也许某人或某事删除了该行并重新插入它,而不是进行实际的更新

Most likely, one of the following options

  • The trigger didn't exist when the row was updated
  • The trigger was disabled when the row was updated
  • Some other SQL statement set lastModified to null

Of course, there is also the possibility that you are not accurately identifying cases where the amount was updated. For example, perhaps someone or something deleted the row and re-inserted it rather than doing an actual update.

很糊涂小朋友 2025-01-21 11:52:38

我可以考虑的几个选项:

  • 触发器在更新之前触发,这意味着INSERT INTO不会触发
  • 在这些amount值之后创建的触发器已更新(因此没有要触发的触发器)
  • 在更新这些 amount 值之前禁用/删除触发器,然后启用/重新创建

Several options I can think about:

  • trigger fires before update, which means that INSERT INTO wouldn't fire it
  • trigger was created AFTER those amount values were updated (so there were no triggers to be fired)
  • trigger was disabled / dropped before those amount values were updated, and then enabled / recreated
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文