Sql 由于After触发器,尝试插入到表中时记录插入失败

Sql 由于After触发器,尝试插入到表中时记录插入失败,sql,oracle,plsql,Sql,Oracle,Plsql,***********************错误消息******************** 可以使用:NEW获取新插入的数据 SQL Error: ORA-04091: table ORA_JSHAH87.CRAFTSHOPITEMS is mutating, trigger/function may not see it ORA-06512: at "ORA_JSHAH87.TRIGGER_CRAFTSHOPITEMS", line 13 ORA-04088: error during e

***********************错误消息********************

可以使用:NEW获取新插入的数据

SQL Error: ORA-04091: table ORA_JSHAH87.CRAFTSHOPITEMS is mutating, trigger/function may not see it
ORA-06512: at "ORA_JSHAH87.TRIGGER_CRAFTSHOPITEMS", line 13
ORA-04088: error during execution of trigger 'ORA_JSHAH87.TRIGGER_CRAFTSHOPITEMS'
04091. 00000 -  "table %s.%s is mutating, trigger/function may not see it"
*Cause:    A trigger (or a user defined plsql function that is referenced in
           this statement) attempted to look at (or modify) a table that was
           in the middle of being modified by the statement which fired it.
*Action:   Rewrite the trigger (or function) so it does not read that table.

您是否清楚了解错误消息?@additionster是正确的。您的代码中仍然存在逻辑错误。select maxrownum不一定返回您的行,但可能返回在语句中插入的任何行。它与您收到的错误消息有关。Oracle不能保证您的代码是确定性的。
SQL Error: ORA-04091: table ORA_JSHAH87.CRAFTSHOPITEMS is mutating, trigger/function may not see it
ORA-06512: at "ORA_JSHAH87.TRIGGER_CRAFTSHOPITEMS", line 13
ORA-04088: error during execution of trigger 'ORA_JSHAH87.TRIGGER_CRAFTSHOPITEMS'
04091. 00000 -  "table %s.%s is mutating, trigger/function may not see it"
*Cause:    A trigger (or a user defined plsql function that is referenced in
           this statement) attempted to look at (or modify) a table that was
           in the middle of being modified by the statement which fired it.
*Action:   Rewrite the trigger (or function) so it does not read that table.
create or replace 
trigger trigger_craftShopItems 
after insert on craftshopitems for each row

declare

user_name varchar2(20);

begin

  select user into user_name from dual;

  dbms_output.put_line('Insert operation performed by :'||user_name);
  dbms_output.put_line('New CraftID: '|| :NEW.craftId);
  dbms_output.put_line('New CraftItemName: '|| :NEW.craftItemName);
  dbms_output.put_line('New CraftVendor: '|| :NEW.CraftVendor);
  dbms_output.put_line('NewCraftStoreId:'|| :NEW.CraftStoreId);  

end trigger_craftShopItems;