之前,我將嘗試使用觸發器來避免在某些情況下在表Products
刪除一排。代碼如下突變表中的觸發器
CREATE TRIGGER trgPreventProductRemoval
BEFORE DELETE ON Products
FOR EACH ROW
BEGIN
DECLARE
l_custid INTEGER;
BEGIN
SELECT count(*) INTO l_custid FROM Orders WHERE product = :old.prodDescription ;
IF l_custid > 0 THEN
raise_application_error (-20100, 'You can not delete a product that has active orders!');
END IF;
END;
END;
但是我得到的錯誤:table ORDERS is mutating, trigger/function may not see it
。
我該如何解決?
編輯-SOLUTION:我已經接受了下面,因爲它是「政治正確」的解決方案。由於某些「限制」,我無法使用它並最終找到了不同的解決方法。看到我單獨發佈的解決方案。
的可能重複的[ORA-04091:表\ [嗒嗒\]被突變,觸發/功能可能無法看到它](http://stackoverflow.com/questions/375968/ora-04091-table-blah-is -mutating-trigger-function-may-not-see-it) – Sathya 2012-01-03 04:15:10