[英]Maintain dependency between two tables while executing triggers in oracle
How we can maintain dependency between two tables while executing triggers in oracle??我们如何在 oracle 中执行触发器时保持两个表之间的依赖关系? As we know we can use follows clause if we have single table and multiple triggers based on that table but my concern is that is there any way if we have 2 different tables and there are different triggers based on these table so how can we maintain some proper sequence in this case.
正如我们所知,如果我们有单个表和基于该表的多个触发器,我们可以使用 follows 子句,但我担心的是,如果我们有 2 个不同的表并且有基于这些表的不同触发器,那么我们如何维护一些在这种情况下的正确顺序。
For example: --Table1:例如:--表 1:
CREATE TABLE emp(
empId number PRIMARY KEY,
FirstName varchar2(20),
LastName varchar2(20),
Email varchar2(25),
PhoneNo varchar2(25),
Salary number(8)
);
--Table 2: --表2:
CREATE TABLE emp_1(
empId number PRIMARY KEY,
FirstName varchar2(20),
LastName varchar2(20),
Email varchar2(25),
PhoneNo varchar2(25),
Salary number(8)
);
Trigger on EMP
: EMP
触发:
CREATE OR replace TRIGGER TRIGGER_emp
BEFORE INSERT OR AFTER UPDATE ON emp
FOR EACH ROW
BEGIN
dbms_output.put_line ('MY EXECUTE ORDER FOR EMP IS SECOND -EXECUTED');
END;
/
Trigger on EMP1
:在
EMP1
上触发:
CREATE OR replace TRIGGER TRIGGER_emp1
BEFOR INSERT OR AFTER UPDATE ON emp_1
FOR EACH ROW
BEGIN
dbms_output.put_line ('MY EXECUTE ORDER FOR EMP IS FIRST -EXECUTED');
END;
/
Now i want this trigger TRIGGER_emp1 will execute first and then this trigger will execute TRIGGER_emp last.现在我希望这个触发器 TRIGGER_emp1 首先执行,然后这个触发器最后执行 TRIGGER_emp。 Is it possible to do so in oracle
oracle可以吗
Please guide me in this.请指导我。
You seem to be a clone of user who recently posted two questions regarding the same subject.您似乎是最近发布了关于同一主题的两个问题的用户的克隆。 It was said that you can't do that.
有人说你不能那样做。 Triggers "belong" to a single table, which means that
触发器“属于”单个表,这意味着
emp
table, which thenemp
表中插入(或更新)值,然后trigger_emp
which does somethingtrigger_emp
做某事
emp1
, trigger trigger_emp1
won't fire - why would it?emp1
没有发生任何事情,触发器trigger_emp1
不会触发 - 为什么会这样?
trigger_emp
) affect rows in emp1
table (insert a row or update existing values)trigger_emp
)影响emp1
表中的行(插入一行或更新现有值)
trigger_emp1
will do whatever it doestrigger_emp1
就会做它所做的一切Maybe, just maybe you should consider creating a stored procedure which contains code that works with rows in both emp
and emp1
table.也许,只是也许您应该考虑创建一个存储过程,其中包含与
emp
和emp1
表中的行一起使用的代码。 Then, instead of relying on triggers and worry whether they will fire, when will they fire and in which sequence, your main transaction would actually call the procedure which would then do the job (and affect rows in emp
and emp1
, in any order you want - that's easy to do as you'd just rearrange statements within the procedure).然后,而不是依赖触发器并担心它们是否会触发,它们何时会触发以及以什么顺序触发,您的主事务实际上会调用该过程,然后执行该工作(并影响
emp
和emp1
中的行,以您的任何顺序想要 - 这很容易做到,因为您只需在过程中重新排列语句)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.