Hello,
I have a very simple table, and want to create a trigger that updates
the date column entry (with the current date), whenever a row gets
modified.
Is there a simple way of fixing this, or would I have to create 3
extra triggers, a package, etc., as described in most posts about
mutating table errors?
Could you please explain to me WHY this error happens here (I have not
been able to find a clear explanation of what causes them)?
create table mvkTest
(bukva char(5),
kogda date);
insert into mvkTest
values('aaa', sysdate);
insert into mvkTest
values('bbb', sysdate);
create or replace trigger test_Trigger
after update on mvkTest
for each row
begin update mvkTest
set kogda = sysdate;
end;
/
update mvkTest
set bukva = 'ccc'
where bukva = 'aaa';
=======>>>>>>
update mvkTest
*
ERROR at line 1:
ORA-04091: table DTI.MVKTEST is mutating, trigger/function may not see
it
ORA-06512: at "DTI.TEST_TRIGGER", line 1
ORA-04088: error during execution of trigger 'DTI.TEST_TRIGGER'
Thank you,
G. 4 7377
"M" <gr**********@yahoo.com> wrote in message
news:c7**************************@posting.google.c om...
| Hello,
|
| I have a very simple table, and want to create a trigger that updates
| the date column entry (with the current date), whenever a row gets
| modified.
| Is there a simple way of fixing this, or would I have to create 3
| extra triggers, a package, etc., as described in most posts about
| mutating table errors?
| Could you please explain to me WHY this error happens here (I have not
| been able to find a clear explanation of what causes them)?
|
|
| create table mvkTest
| (bukva char(5),
| kogda date);
|
| insert into mvkTest
| values('aaa', sysdate);
| insert into mvkTest
| values('bbb', sysdate);
|
| create or replace trigger test_Trigger
| after update on mvkTest
| for each row
| begin update mvkTest
| set kogda = sysdate;
| end;
| /
|
| update mvkTest
| set bukva = 'ccc'
| where bukva = 'aaa';
|
| =======>>>>>>
|
| update mvkTest
| *
| ERROR at line 1:
| ORA-04091: table DTI.MVKTEST is mutating, trigger/function may not see
| it
| ORA-06512: at "DTI.TEST_TRIGGER", line 1
| ORA-04088: error during execution of trigger 'DTI.TEST_TRIGGER'
|
|
|
| Thank you,
| G.
are you used to SQL Server where you have the pseudo-tables for accessing
rows affected by the DML?
in Oracle you reference the values going into the database with the :NEW
'record' and the original values with the :OLD 'record'
so the trigger is more like
create or replace trigger test_trigger
before insert or update on mvktest
for each row
begin
:new.kogda := sysdate;
end;
simple, no?
your code, if it would work, would have updated every row in the table (no
where clause)
note:
[_] use a BEFORE trigger to set values before the DML is applied to the
database
[_] use 'INSERT or UPDATE' for a trigger that applies to both DML
[_] optionally use the INSERTING and UPDATING keywords (if inserting....)
for conditional logic in the same trigger
-- mcs
Hello,
In
create or replace trigger test_Trigger
after update on mvkTest
for each row
begin update mvkTest
set kogda = sysdate;
end;
.... you are trying to update a table which is in the process of being
changed by the triggering statement and this causes the 'mutating' error.
For a discussion, see http://asktom.oracle.com/pls/ask/f?p...9::NO::F4950_P
8_DISPLAYID,F4950_P8_CRITERIA:9579487119866,
In your case, it's unclear why you need a trigger at all since you can just
use the default of 'SYSDATE' on the column in question...
VC
"M" <gr**********@yahoo.com> wrote in message
news:c7**************************@posting.google.c om... Hello,
I have a very simple table, and want to create a trigger that updates the date column entry (with the current date), whenever a row gets modified. Is there a simple way of fixing this, or would I have to create 3 extra triggers, a package, etc., as described in most posts about mutating table errors? Could you please explain to me WHY this error happens here (I have not been able to find a clear explanation of what causes them)?
create table mvkTest (bukva char(5), kogda date);
insert into mvkTest values('aaa', sysdate); insert into mvkTest values('bbb', sysdate);
create or replace trigger test_Trigger after update on mvkTest for each row begin update mvkTest set kogda = sysdate; end; /
update mvkTest set bukva = 'ccc' where bukva = 'aaa';
=======>>>>>>
update mvkTest * ERROR at line 1: ORA-04091: table DTI.MVKTEST is mutating, trigger/function may not see it ORA-06512: at "DTI.TEST_TRIGGER", line 1 ORA-04088: error during execution of trigger 'DTI.TEST_TRIGGER' Thank you, G.
"VC" <bo*******@hotmail.com> wrote in message
news:iUxYb.208484$U%5.1156019@attbi_s03...
| Hello,
|
| In
|
| create or replace trigger test_Trigger
| after update on mvkTest
| for each row
| begin update mvkTest
| set kogda = sysdate;
| end;
|
| ... you are trying to update a table which is in the process of being
| changed by the triggering statement and this causes the 'mutating' error.
| For a discussion, see
| http://asktom.oracle.com/pls/ask/f?p...9::NO::F4950_P
| 8_DISPLAYID,F4950_P8_CRITERIA:9579487119866,
|
|
| In your case, it's unclear why you need a trigger at all since you can
just
| use the default of 'SYSDATE' on the column in question...
|
| VC
|
actually, there are two issues with using a default value instead of a
trigger
1) it can be overridden on INSERT (including with an explicit null)
2) it only works on INSERT, not on UPDATE
a trigger is the only way to guarantee that a value is set, outside of
limiting all access to an API (for which there are many valid arguments)
-- mcs
Hello,
"Mark C. Stock" <mcstockX@Xenquery .com> wrote in message
news:Ue********************@comcast.com... "VC" <bo*******@hotmail.com> wrote in message news:iUxYb.208484$U%5.1156019@attbi_s03... | Hello, | | In | | create or replace trigger test_Trigger | after update on mvkTest | for each row | begin update mvkTest | set kogda = sysdate; | end; | | ... you are trying to update a table which is in the process of being | changed by the triggering statement and this causes the 'mutating'
error. | For a discussion, see | http://asktom.oracle.com/pls/ask/f?p...9::NO::F4950_P | 8_DISPLAYID,F4950_P8_CRITERIA:9579487119866, | | | In your case, it's unclear why you need a trigger at all since you can just | use the default of 'SYSDATE' on the column in question... | | VC |
actually, there are two issues with using a default value instead of a trigger
1) it can be overridden on INSERT (including with an explicit null) 2) it only works on INSERT, not on UPDATE
Agree. I missed the update part ;)
a trigger is the only way to guarantee that a value is set, outside of limiting all access to an API (for which there are many valid arguments)
-- mcs
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: robert |
last post by:
i've found the solution threads on changing a column on insert. works
fine.
question:
- will one package serve for all such triggers, or does there need to
be a package defined to support...
|
by: M Mueller |
last post by:
Hello -
I'm using Oracle 8i and am running into the infamous mutating table
error on an AFTER INSERT OR UPDATE FOR EACH ROW trigger. I have seen
examples for getting around mutating table...
|
by: hankr |
last post by:
I have only a developer's level knowledge of Oracle, though I have access to
DBA tools. Searches through the docs have not been fruitful, so I thought
I'd try here.
I am getting an error on a...
|
by: Reshmi Jacob |
last post by:
Hello,
Can any one help me in creating a trigger to update system date into a table while inserting a record into that table. I tried it like this, it is showing error !!!
The following error...
|
by: AYAN MUKHERJEE |
last post by:
I have 2 tables. 1) emp_test, 2) newemp_test. I had created a trigger to insert automatic data in the table no. 2 , as soon as a row of information is inserted in table no. 1. The Trigger had been...
|
by: extremexpert |
last post by:
Hai all,
I have two tables like hdr and det. I would like to create the trigger for the situation ' 1.Delete Det table records, if any record is deleting in hdr table 2. Delte hdr table...
|
by: dmanojbaba |
last post by:
i have a table with values like 1,2,3.... (primary key)
if i delete a row eg.4,
i need my trigger to update the values 5 to 4,6 to 5, 7 to 6,.. like that, after deleting 4.
pls help me...
my...
|
by: M |
last post by:
Hello,
I have a very simple table, and want to create a trigger that updates
the date column entry (with the current date), whenever a row gets
modified.
Is there a simple way of fixing this,...
|
by: vamsioracle |
last post by:
Can Someone help me how to avoid mutating error while using triggers.
I work on oracle apps. I created a vacation rule such that responsibility is delegated to other person. These details are...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |