CREATE TRIGGER x AFTER INSERT ON itemtype
FOR EACH ROW
DECLARE
minn itemtype.PRICE%type;
BEGIN
select MIN(itemtype.PRICE) into minn from itemtype;
IF (:new.PRICE > minn*4) then RAISERROR('Custom text');
END IF;
END;
/ 我正在尝试创建一个触发器,当我尝试将一个新条目插入到itemtype中,并且itemtype.PRICE列值大于表中当前低价商品的4倍时,该触发器会引发错误。
当我尝试创建触发器时,我得到了这些编译错误。
LINE/COL ERROR
-------- --------------------------------------------------------------
5/31 PL/SQL: Statement ignored
5/31 PLS-00201: identifier 'RAISERROR' must be declared我也试过
CREATE TRIGGER x AFTER INSERT ON itemtype
FOR EACH ROW
DECLARE
minn itemtype.PRICE%type;
BEGIN
select MIN(itemtype.PRICE) into minn from itemtype;
if (:new.PRICE > minn*4) then raise_application_error(-20010,'Too Expensive');
END IF;
END;
/这是符合的,但是当我尝试向表中插入一个新条目时,我得到了这些错误,说明我的触发器失败了。
SQL> insert into itemtype(ITEMNUM,NAME,PICTURE,PRICE,BELONGSTO ) VALUES ('A11','The who knows','',10.99,'P');
insert into itemtype(ITEMNUM,NAME,PICTURE,PRICE,BELONGSTO ) VALUES ('A11','The who knows','',10.99,'P')
*
ERROR at line 1:
ORA-04091: table USERNAME.ITEMTYPE is mutating, trigger/function may not see it
ORA-06512: at "USERNAME.X", line 5
ORA-04088: error during execution of trigger 'USERNAME.X'发布于 2017-12-06 15:05:01
尝试在触发器中使用PRAGMA AUTONOMOUS_TRANSACTION。
看看我对这个问题的回答:SQL trigger on delete mutating table
https://stackoverflow.com/questions/47662866
复制相似问题