Home » SQL & PL/SQL » SQL & PL/SQL » Error ORA-04091
Error ORA-04091 [message #598399] Mon, 14 October 2013 09:45 Go to next message
andreacaffy
Messages: 5
Registered: October 2013
Junior Member
I have a problem: i receive this error.
table TableName is mutating, trigger/function may not see it.

The problem is that I try to execute a stored procedure extracting data from the same table.

My table have a trigger before on insert for each row
begin
  :new.pl_id := ppe_seq_pl_id.nextval;
end;
/


where ppe_seq_pl_id is a sequence.

I read that is possible to resolve that problem creating a Package. But I try withouth success.
Can you help me?



Re: Error ORA-04091 [message #598404 is a reply to message #598399] Mon, 14 October 2013 10:06 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
What are you doing in the procedure? When you have a trigger on a table you cannot do SELECT on the table inside the trigger.

Post the complete trigger code and what you are doing inside the procedure.

[Updated on: Mon, 14 October 2013 10:06]

Report message to a moderator

Re: Error ORA-04091 [message #598405 is a reply to message #598399] Mon, 14 October 2013 10:12 Go to previous messageGo to next message
andreacaffy
Messages: 5
Registered: October 2013
Junior Member
In my procedure I need to insert many rows than the values of Field1

scen, dat, descr are string.
CALC_TOTAL_ACC and CALC_MONTH_LENGHT are functions
idinput is a parameter passed to the procedure

INSERT INTO TableRows (R_ID, Field1, Field2, Field3, Field4, Field5, Field6, Field7, Total1, Total2, Field8)
SELECT R_ID, FIEDL1, scen, dat, dat, '-','','Actual',case when 0.8*CALC_TOTAL_ACC(idinput,'Budget',field1)/CALC_MONTH_LENGTH(idinput) < 0 then 
		0 else 0.8*CALC_TOTAL_ACC(idinput,'Budget',field1)/CALC_MONTH_LENGTH(idinput) end,
		case when 0.8*CALC_TOTAL_ACC(idinput,'Budget',field1)/CALC_MONTH_LENGTH(idinput) < 0 
		then 0.8*CALC_TOTAL_ACC(idinput,'Budget',field1)/CALC_MONTH_LENGTH(idinput) else 0 end
		, descr FROM TableRows WHERE R_ID=idinput GROUP BY Field1, R_ID;
Re: Error ORA-04091 [message #598409 is a reply to message #598405] Mon, 14 October 2013 10:31 Go to previous messageGo to next message
andreacaffy
Messages: 5
Registered: October 2013
Junior Member

CREATE OR REPLACE TRIGGER TRIGGERNAME BEFORE INSERT ON TableRows REFERENCING OLD AS "OLD" NEW AS "NEW" FOR EACH ROW
begin
  :new.id := seq_id.nextval;
end;
/



and the sequence

CREATE SEQUENCE SEQ_ID
  START WITH 2155430
  MAXVALUE 9999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  ORDER;

[Updated on: Mon, 14 October 2013 10:32]

Report message to a moderator

Re: Error ORA-04091 [message #598410 is a reply to message #598409] Mon, 14 October 2013 10:33 Go to previous messageGo to next message
andreacaffy
Messages: 5
Registered: October 2013
Junior Member
The problem appears in the procedure with CALC_TOTAL_ACC(idinput,'Budget',field1) code.
Re: Error ORA-04091 [message #598412 is a reply to message #598410] Mon, 14 October 2013 10:51 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
ANDREA,
how can we reproduce what you report?

we need CREATE TABLE statement(s) source code for all procedures involved
Re: Error ORA-04091 [message #598414 is a reply to message #598410] Mon, 14 October 2013 10:52 Go to previous messageGo to next message
andreacaffy
Messages: 5
Registered: October 2013
Junior Member
CALC_MONT_LENGTH is linked to TableMaster and return difference between two dates in month.

CALC_TOTAL_ACC is
CREATE OR REPLACE FUNCTION CALC_TOTAL_ACC(
    idinput IN       VARCHAR2,
    param1 IN VARCHAR2,
    param2 IN VARCHAR2    
) RETURN number
IS

tot number;

BEGIN

  SELECT  nvl(SUM(total1),0) - nvl(SUM(total2),0) into tot FROM TableRows WHERE r_id= idinput and lower(field2)=lower(param1)
  and lower(field1)=lower(param2);
  return tot;

end;
/
icon11.gif  Re: Error ORA-04091 [message #598416 is a reply to message #598414] Mon, 14 October 2013 10:56 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

In the end, you wrote many posts but we are unable to see, and even less execute and reproduce what you did and got.
Please repost a complete test case with CREATE statements for ALL objects.
use SQL*Plus and copy and paste the whole session that leads to the error.
Previous Topic: Procedure Calling Methods
Next Topic: Dynamic column in SQL Output
Goto Forum:
  


Current Time: Thu Apr 18 19:20:42 CDT 2024