Oracle中约束检查之前触发器执行之后

发布于 2024-08-29 20:38:55 字数 251 浏览 4 评论 0原文

我在表 T1 上有插入/更新后触发器,它从 T2 获取 Col1 的参考数据,并执行一些工作并将其插入到另一个表中。 col1 是表 T2 的 FK。

当用户将不正确或不存在的值插入到 Col1 中并且禁用触发器时,我会收到约束错误,这很好。

但是,当启用触发器并且用户在 Col1 中插入错误值时,触发器将被触发并显示“未找到数据”错误消息。

实际上我期望表抛出约束错误,但触发器抛出它。

请让我知道您对此触发行为的评论。

I have After Insert/Update trigger on Table T1 which get the referential data for Col1 from T2 and does some work and insert it into another table.
The col1 is FK to Table T2.

When user insert the incorrect or non existing value into the Col1 and if trigger is disabled I am getting constraint error that is fine.

But when trigger is enabled and user insert the wrong value in Col1 trigger is getting fired and shows the 'no data found' error message.

Actually I am expecting the table to throw constraint error, but trigger is throwing it.

Please let me know your comments about this trigger behaviour.

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

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

发布评论

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

评论(2

極樂鬼 2024-09-05 20:38:55

您没有提及您是使用 BEFORE 还是 AFTER 触发器。请查看文档了解执行顺序

  • BEFORE 语句
  • BEFORE 行
  • CONSTRAINTS
  • AFTER 行
  • AFTER 语句

You do not mention whether you are using BEFORE or AFTER triggers. Please check the documentation for the order of execution:

  • BEFORE statement
  • BEFORE row
  • CONSTRAINTS
  • AFTER row
  • AFTER statement
单调的奢华 2024-09-05 20:38:55

我猜测触发器必须是 BEFORE 触发器。它将在检查约束之前运行。如果触发器引发NO_DATA_FOUND,则永远不会检查约束。如果触发器被禁用,则它不会运行,因此会检查约束。

I'm guessing the trigger would have to be a BEFORE trigger. It will run prior to the constraints being checked. If the trigger raises NO_DATA_FOUND, then the constraint never gets checked. If the trigger is disabled, it is not run, so the constraint gets checked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文