0
I’m having the following error while running my Rigger, how could I resolve?
ERROR
Error when I give Insert in the purchasing table INSERT into compra_product (CPR_CODIGO, PRO_CODIGO,CPP_QTDE, CPP_PRECO,CPP_DESCONTO) VALUES (1,2,7,87,0); ORA-04091: the table ADMIN.COMPRA_PRODUTO is mutant; maybe the trigger/function cannot locate it ORA-06512: in "ADMIN.TRG_TOTAL_COMPRA_PRODUTO", line 3 ORA-04088: error while executing trigger 'ADMIN.TRG_TOTAL_COMPRA_PRODUTO'
TRIGGER
CREATE OR REPLACE TRIGGER "TRG_TOTAL_COMPRA_PRODUTO"
BEFORE INSERT OR DELETE OR UPDATE ON COMPRA_PRODUTO
FOR EACH ROW
DECLARE
BEGIN
UPDATE COMPRA_PRODUTO SET CPP_TOTAL =
(
SELECT ((CPP_TOTAL * CPP_QTDE) - (((CPP_TOTAL * CPP_QTDE) * CPP_DESCONTO) / 100)) FROM COMPRA_PRODUTO
WHERE CPP_CODIGO = :NEW.CPP_CODIGO AND
PRO_CODIGO = :NEW.PRO_CODIGO
)
WHERE CPR_CODIGO = :NEW.CPR_CODIGO;
END;
Insert
INSERT INTO COMPRA_PRODUTO (CPR_CODIGO, PRO_CODIGO, CPP_QTDE, CPP_PRECO, CPP_DESCONTO)
VALUES (1,3,9,90, 0);
Which doubt??
– user94991
Da erro quando dou insert na tabela compra_produto para calcular total
INSERT into compra_produto (CPR_CODIGO, PRO_CODIGO,CPP_QTDE, CPP_PRECO,CPP_DESCONTO)
 VALUES (1,2,7,87,0);

ORA-04091: a tabela ADMIN.COMPRA_PRODUTO é mutante; maybe the trigger/function cannot locate it ORA-06512: in "ADMIN.TRG_TOTAL_COMPRA_PRODUTO", line 3 ORA-04088: error while executing 'ADMIN.TRG_TOTAL_COMPRA_PRODUTO'
– Gabriel Alves
It seems that the table is not in the same schema. Create a public synonym for the COMPRA_PRODUTO table and try again. Oracle Docs: https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_7001.htm
– Andre Mesquita
there’s only one scheme, I’ve heard about making select on the same table as Rigger, I can’t do it?
– Gabriel Alves