table 上的 Oracle Apex 第二个触发器抛出变异错误

Oracle Apex second Trigger on table throwing mutating error

我有 table p_it_people 结构如下,并在其上创建了触发器。

CREATE TABLE  "P_IT_PEOPLE" 
   (    "PERSON_ID" NUMBER NOT NULL ENABLE, 
    "PERSON_NAME" VARCHAR2(255) NOT NULL ENABLE, 
    "PERSON_EMAIL" VARCHAR2(255) NOT NULL ENABLE, 
    "PERSON_ROLE" VARCHAR2(30) NOT NULL ENABLE, 
    "USERNAME" VARCHAR2(255) NOT NULL ENABLE, 
    "ASSIGNED_DEPT" NUMBER, 
    "CREATED_ON" DATE NOT NULL ENABLE, 
    "CREATED_BY" VARCHAR2(255) NOT NULL ENABLE, 
    "MODIFIED_ON" DATE, 
    "MODIFIED_BY" VARCHAR2(255), 
    "PERSON_PASSWORD" VARCHAR2(100), 
    "APPROVER" VARCHAR2(50), 
     CONSTRAINT "P_IT_PEOPLE_PK" PRIMARY KEY ("PERSON_ID")
  USING INDEX  ENABLE, 
     CONSTRAINT "P_IT_PEOPLE_NAME_UK" UNIQUE ("PERSON_NAME")
  USING INDEX  ENABLE, 
     CONSTRAINT "P_IT_PEOPLE_USERNAME_UK" UNIQUE ("USERNAME")

table 上的现有触发器:

CREATE OR REPLACE EDITIONABLE TRIGGER  "P_IT_PEOPLE_BIU" 
before insert or update on p_it_people
for each row
begin
if inserting then
if :NEW.PERSON_ID is null then
:NEW.PERSON_ID := it_api.gen_pk;
end if;
:NEW.CREATED_ON := sysdate;
:NEW.CREATED_BY := nvl(v('APP_USER'),USER);
end if;
if updating then
:NEW.MODIFIED_ON := sysdate;
:NEW.MODIFIED_BY := nvl(v('APP_USER'),USER);
end if;
end;

除此之外,我想创建另一个触发器,它会在有新条目时发送电子邮件。 我部署了这个触发器:

CREATE OR REPLACE EDITIONABLE TRIGGER  "P_IT_ISSUES_AIU_NEW_PASSWORD" 
AFTER 
insert  on P_IT_PEOPLE
for each row 
DECLARE 
v_person_id number;
v_username varchar2(50);
v_Email varchar2(255);
Begin
select person_id,username,person_email into v_person_id,v_username,v_email from p_it_people where person_id=v_person_id;

             APEX_MAIL.SEND( 
                 p_to => v_email, 
                 p_from => v_email, 
                 p_body =>  'Your account has been created  ' ||chr(10)|| 
                 ' Username'|| v_username||chr(10)|| 
                 ' Password'||v_username  ,
                  p_subj => 'New User'); 

end;

现在,当我尝试插入行时,它抛出错误 - p_it_people 正在发生变化。我该如何应对?

您选择的 table 与行级触发器触发的相同 - 正是导致 "table is mutating" 的原因。但在这种情况下,你甚至不需要。只需像这样使用 :NEW 伪记录:

CREATE OR REPLACE EDITIONABLE TRIGGER  "P_IT_ISSUES_AIU_NEW_PASSWORD" 
AFTER 
insert  on P_IT_PEOPLE
for each row 
Begin
             APEX_MAIL.SEND( 
                 p_to => :NEW.person_email,
                 p_from => :NEW.person_email , 
                 p_body =>  'Your account has been created  ' ||chr(10)|| 
                 ' Username'|| :NEW.username||chr(10)|| 
                 ' Password'||:NEW.username  ,
                  p_subj => 'New User'); 

end;