Search avdeo.com
Categories
F.R.I.E.N.D.S
Important Links
Interview Questions
Oracle Sites
Subscription
Category Cloud
Database 10g Performance Tuning Fusion Middleware (FMW) General Interview Questions JavaScript Linux System Administration Oracle Application Express Oracle Application R12 Oracle Applications 11i Oracle Database 9i Oracle Database 10g Oracle Database 11g Oracle Middleware Oracle RAC ORA Errors timesten XSLT
F.R.I.E.N.D.S
Important Links
Interview Questions
Oracle Sites
Subscription
Recent Posts
- Inside Index block – Oracle Database 11g
- Oracle SQL Plan Management – Part 3
- Oracle SQL Plan Management – Part 2
- Oracle SQL Plan Management – Part 1
- Creating Standby database using Active Duplication – Oracle Database 11g
- Avoiding “no data found” : Tips
- An insight into Oracle Index rebuild
- Exchange Partition in Oracle
- Virual Index and Invisible Index
- Oracle Index rebuild online – 10g Vs 11g
- WARNING: inbound connection timed out (ORA-3136)
- Oracle Database 11g new feature – Automatic Memory Management
Archives
- December 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- January 2011
- November 2010
- May 2010
- April 2010
- February 2010
- January 2010
- December 2009
- September 2009
- August 2009
- June 2009
- May 2009
- April 2009
- January 2009
- December 2008
- November 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
Top Posts
- Reducing datafile size to recover free space - Oracle Database 10g
- Uploading excel sheet using Oracle Application Express (APEX)
- Oracle E-Business Suite R12 - Profiles
- OPATCH Utility (Oracle RDBMS Patching)
- Oracle Database 9i - Basic Architecture
- Oracle Password Encryption and Hashing
- Oracle Index rebuild online - 10g Vs 11g
- Handling Large Objects (LOB) - Oracle Database 10g
- Installing Oracle Data Integrator (ODI)
- Converting a Single Instance Database to RAC Manually - Oracle RAC 10g
Actually , there is another way – Oracle 9i release 2 onwards
use a PRAGMA AUTONOMOUS_TRANSACTION before the query in the
mutating trigger
then you can query the same table –
But if you try to insert / update the same table , it will fail
Instead of creating two / three more triggers , use an AUTONOMOUS TRANSACTION
, plus point here is that you can COMMIT inside the trigger as well
how to use using AUTONOMOUS TRANSACTION. can you explain with some example please.
thanks a lot
Thank you a lot, both blogger and commenter
about the PRAGMA AUTONOMOUS_TRANSACTION, i am confused about how to change this case to the
autonomous
i found an example from Oracle Document
The following example lets a trigger issue transaction control statements:
CREATE TABLE anniversaries AS
SELECT DISTINCT TRUNC(hire_date) anniversary FROM employees;
ALTER TABLE anniversaries ADD PRIMARY KEY (anniversary);
CREATE TRIGGER anniversary_trigger
BEFORE INSERT ON employees FOR EACH ROW
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
INSERT INTO anniversaries VALUES(TRUNC(:new.hire_date));
– Only commits the preceding INSERT, not the INSERT that fired
– the trigger.
COMMIT;
EXCEPTION
– If someone else was hired on the same day, we get an exception
– because of duplicate values. That’s OK, no action needed.
WHEN OTHERS THEN NULL;
END;
but how to do insering table as independtent behavior and commit first, then use the new inserted data to insert to the other table, as this article said.
by the way, is there any other solution for this case??
is anybody heared “temporary table” and maybe it is other solution
St_Bal|Clearing|Funding|Adj_Credit|Adj_Debit|Cl_Bal|Date |
————————————————————–
10.00 | 0.00 | 0.00 | 0.00 | 0.00 | 10.00| 01/01/08 |
—————————————————————
10.00 | 0.00 |100.00 | 0.00 | 0.00 |110.00| 01/02/08 |
—————————————————————
110.00| 0.00 | 0.00 | 10.00 | 0.00 | 100.00|01/03/08|
—————————————————————
Now If someone goes to record of 01/01/08 and update the value of starting balance to 20.00 from 10.00
i need to write trigger to do update all next onward data .that but it gives me error
ORA-04091: table is mutating, trigger/function may not see it.
and if i do the way discuss above it gives error that update exceed the limit
any idea how to figure it out !! ?
Hi,
I need to write an AFTER INSERT triiger on table1 FOR EACH ROW and then need to uodate the table1 itself inside the trigger.
Can you please guide me how will it be possible?
Thanks
That doesn’t make sense to me. The mutating table error is caused by selecting from the table that is mutating. Your solution is a convoluted way of just inserting the value :new.col2. Why do you need to use a package and a statement level trigger to get that value? Your solution has totally removed the select altogether so why not just do that in the code you used to highlight the original problem
I have a problem with a mutating table error. I have to select from the mutating table and an autonomous transaction wont work because I cant select from the mutating table during an autonomous transaction as the record won’t have been committed by this point.
I am stumped!!!!
I do apologise. It works. Problem solved. Thank you very much!
Paul.
PRAGMA AUTONOMOUS_TRANSACTION;
is superb man…. thanks
is there any side effect for it?
Good posting solution of ORA-04091 error.
Great post and comments! However, I have a question:
Is the original post (with the package variable) thread-save? Would two parallel inserts mess each other up as both are setting the package variable? Or are the variables bound to a session?
Yeah,
I have a function that returns a kind of flag to tell me if updated record is of particular type. Couldn’t write normal where statement as this is dynamic query that doesn’t have enough information. Obviously, despite the fact that in function I don’t use any of updated columns I was getting ORA-04091. Autonomous transaction helped! Thanks!
CREATE table ABC
( abc_id number(10) primary key,
abc_name varchar2(30)
);
create table XYZ
( xyz_id number(10) not null,
xyz_name varchar2(30) ,
foreign key(xyz_id) references ABC(abc_id) on delete cascade
);
I want to create a trigger such that in table XYZ the last reccord is deleted then corresponding reccord in table ABC should be deleted but i keep getting mutilating error can ny one help me out .
Create or replace trigger backup after
delete on XYZ for each row
DECLARE
N INTEGER;
begin
commit;
SELECT COUNT(*) INTO N FROM XYZ WHERE XYZ_id=:old.xyz_id;
if (N=1) THEN
DELETE FROM ABC WHERE ABC_ID=:old.xyz_id;
end if;
end;