我试图编写一个触发器,当用户在同一张表内插入或更新一行时,该触发器将更新一列。示例:插入用户(ID,F_NM,L_NM,EMAIL)值(“ 1”,“ John”,“ Doe”,“ [email protected]”);插入后,我要调用:更新用户集ORG ='market',其中ID ='1'。
create or replace trigger user_change
after insert or update of EMAIL on USER
for each row
declare
NEW_ORG VARCHAR(10);
BEGIN
CASE
when :NEW.EMAIL like '[email protected]' then
NEW_ORG := 'market';
........
END CASE;
UPDATE USER set ORG = NEW_ORG where ID = :NEW.ID
END;
计算新的ORG工作,但是我无法使update语句正常工作。我收到“ ORA-04091表USER正在变异,触发器/功能可能看不到它”,这是由于我同时插入/更新同一记录而引起的。尝试在触发器中添加“ pragma automation_transaction”和“ commit”,字段的插入/更新有效,但ORG不会更新。
还尝试更改为INSTEAD OF INSERT或UPDATE EMAIL,但我不断收到“ ORA-04073列列表对此触发器类型无效”
create or replace trigger user_change
instead of insert or update of EMAIL on USER
虽然我得到“ ORA-25002无法在表上创建而不是触发器”
create or replace trigger user_change
instead of insert on USER
当您可以在写入之前设置值时,为什么不简单地将触发器转换为之前触发器呢?这样,您无需在表上运行新的DML语句,从而避免了“变异”错误。
create or replace trigger user_change
after insert or update of email on user
for each row
begin
if :new.email like '%@market.org.com' then
:new.org := 'market';
end if;
end;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句