Home » SQL & PL/SQL » SQL & PL/SQL » mutating ....
mutating .... [message #4682] |
Tue, 07 January 2003 23:11  |
gururaj
Messages: 8 Registered: August 2002
|
Junior Member |
|
|
hi,
i am new to oracle and came across terms mutating and constraining tables.can any body explain me about these and when do they come into picture.
thanks in advance.
|
|
|
Re: mutating .... [message #4683 is a reply to message #4682] |
Wed, 08 January 2003 00:25   |
 |
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
A mutating table is a table that is currently being modified by an update, delete, or insert statement. You will encounter the ORA-4091 error if you have a row trigger that reads or modifies the mutating table.
A constraining table is a table that a triggering statement might need to read either directly, for a SQL statement, or indirectly, for a declarative referential integrity constraint. A table is mutating or constraining only to the session that issued the statement in progress.
For example, if your trigger contains a select statement or an update statement referencing the table it is triggering off of you will receive the error. Another way this error can occur is if the trigger has statements to change the primary, foreign or unique key columns of the table the trigger is triggering off of.
The basic rule that the data throughout a session is consistent cannot be guaranteed by Oracle if one of the tables you need for a DML operation is being modified in the same operation. Therefor, Oracle won't accept the statement.
HTH,
MHE
|
|
|
|
Re: mutating .... [message #4722 is a reply to message #4686] |
Fri, 10 January 2003 01:01  |
 |
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
It all depends on what type of trigger you're using.
Look at the following demo script:
The table is a stripped-down version of what could be a table that contains the total hours one person has worked during a week.
In the trigger you want to get the total hours_worked for a certain name ( e.g. to calculate overtime). So, you're trying to check with every insert whether a certain person didn't pass 50 hours in total.
WHENEVER SQLERROR CONTINUE
create table mhe_test( id number not null
, name varchar2(50)
, hours_worked number
)
/
CREATE TRIGGER BRI_MHE
AFTER INSERT ON MHE_TEST
FOR EACH ROW
Declare
Cursor c_total_hours
is
Select sum(hours_worked)
From mhe_test
WHERE name = :new.name;
v_total number;
Begin
Open c_total_hours;
Fetch c_total_hours Into v_total;
Close c_total_hours;
-- do some processing
If v_total > 50 Then
Null;
End if;
End;
/
Insert into mhe_test values(1,'MHE1',3);
Insert into mhe_test values(2,'MHE2',7);
Drop table mhe_test
/
When you execute the script it will generate a 'mutating table' error.
If you look at the Oracle online documentation, you'll find more info.
Additional links: Ask Tom 1
Ask Tom 2
MHE
[Updated on: Sat, 26 November 2005 02:21] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Jul 13 00:26:24 CDT 2025
|