ORA-4091- Mutating Trigger Error [message #607435] |
Thu, 06 February 2014 09:51  |
 |
praveenramaswamy
Messages: 34 Registered: December 2013
|
Member |
|
|
CREATE OR REPLACE TRIGGER boin_af_rw_all_1
AFTER INSERT OR UPDATE ON book_inventory
FOR EACH ROW
DECLARE
CURSOR c_prod IS
SELECT prod.prds_product_code, prod.item_number
FROM products prod
WHERE :NEW.prod_prds_product_code = prod.prds_product_code
AND (:NEW.prod_item_number = prod.item_number);
CURSOR c_boin is
SELECT boin.quantity_on_hand, boin.reorder_point
FROM book_inventory boin, products prod
WHERE :NEW.prod_prds_product_code = prod.prds_product_code
AND :NEW.prod_item_number = prod.item_number
AND boin.Prod_Prds_Product_Code = prod.prds_product_code
AND boin.prod_item_number = prod.item_number;
BEGIN
OPEN c_prod;
FETCH c_prod
INTO v_prod_code, v_item_no; /*, v_qty_onhand, v_reorder_pnt*/
CLOSE c_prod;
OPEN c_boin;
FETCH c_boin
INTO v_qty_onhand, v_reorder_pnt;
CLOSE c_boin;
IF v_qty_onhand < v_reorder_pnt THEN
v_message_text := PKG_CCH_GLOBAL.FCT_RET_MESSAGE('05000');
INSERT INTO test67443
(description, col1, col2, col3, col4, col5, col6)
values
('2',
v_prod_code,
v_item_no,
v_qty_onhand,
v_reorder_pnt,
v_message_text,
null);
END IF;
END;
Dear Experts
Please find the Trigger Code above. When i try to insert a record into the "Book_Inventory" Table, i get the error ORA-04091 - Mutating Trigger Error. I know the reason that i am fetching a value from the table(refer cursor c_boin) on which the trigger is built. However don't know how to fix it, because i need those 2 values only from this table. Can you please help me as to how i can modify this trigger.
Thanks
|
|
|
|
|
|
|
|
|
|
|
|
Re: ORA-4091- Mutating Trigger Error [message #607446 is a reply to message #607445] |
Thu, 06 February 2014 11:36   |
cookiemonster
Messages: 13966 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
More to the point, if they're part of the row that caused the trigger to fire, why are you trying to select them at all?
You can reference them directly just like prod_prds_product_code and prod_item_number.
|
|
|
Re: ORA-4091- Mutating Trigger Error [message #607656 is a reply to message #607435] |
Mon, 10 February 2014 12:12  |
 |
praveenramaswamy
Messages: 34 Registered: December 2013
|
Member |
|
|
Dear Experts
Thanks for taking your time and sorry for unable to respond earlier. I have fixed my problem(may be i didnt make myself clear). What i did was crated a before insert trigger on the table and i insert into a temp table.
Then i created an afterinsert trigger and i use this temp table in my cursor query. I didnt get the error and was able to accomplish what i wanted to do.
Thanks once again for your time and inputs.
Cheers
Praveen
|
|
|