Home » SQL & PL/SQL » SQL & PL/SQL » Pragma Autonomous_transaction
Pragma Autonomous_transaction [message #607727] Tue, 11 February 2014 08:23 Go to next message
vaibhav15211
Messages: 38
Registered: August 2012
Location: Hyderabad
Member
Hello,

I am having an on insert trigger TR1 on TB1. A procedure P1 is called from this TR1 which inserts data from TB1 into TB2 after validations.For the validations purpose the TB1 is again referred in the Procedure and thus it was throwing table mutating error. To handle this I made the procedure as pragma autonomous_transaction.
Now the issue is that if I insert 1 line I1, in TB1 then the results in TB2 are reflected after I insert the second line I2 in T1 and so on and so forth.

I am not sure why this is happening.

Please suggest.

Thanks,
Vaibhav
Re: Pragma Autonomous_transaction [message #607728 is a reply to message #607727] Tue, 11 February 2014 08:26 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>I am not sure why this is happening.

I am not sure what is happening.
What problem needs to be solved?

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: Pragma Autonomous_transaction [message #607732 is a reply to message #607727] Tue, 11 February 2014 08:36 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I'm sure what you do is wrong.

Re: Pragma Autonomous_transaction [message #607733 is a reply to message #607732] Tue, 11 February 2014 08:40 Go to previous messageGo to next message
vaibhav15211
Messages: 38
Registered: August 2012
Location: Hyderabad
Member
That's so nice of you to point out my mistake. But what is the mistake ,if you can point out will be really helpful.
Re: Pragma Autonomous_transaction [message #607734 is a reply to message #607733] Tue, 11 February 2014 08:42 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: Pragma Autonomous_transaction [message #607736 is a reply to message #607727] Tue, 11 February 2014 08:44 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
If those validations only involve the newly inserted row, do not 'refer' TB1 in the procedure and pass all used column values into P1 as parameters.

If the SELECT inside P1 queries another row(s) of TB1, you have serial design issue (most probably the table is not in the 1st Normal Form), so the data model should be changed.
Re: Pragma Autonomous_transaction [message #607737 is a reply to message #607727] Tue, 11 February 2014 08:50 Go to previous messageGo to next message
John Watson
Messages: 8929
Registered: January 2010
Location: Global Village
Senior Member
In my experience, when people have problems like this it is because they are mis-using SQL. SQL is a set oriented language, and you are trying to force it to do row-by-row processing. That is never going to work well.

In this case, you probably should be doing a multi-table insert with an error logging clause, and not using a trigger at all:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_9014.htm#SQLRF55088
Re: Pragma Autonomous_transaction [message #607739 is a reply to message #607733] Tue, 11 February 2014 09:03 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

vaibhav15211 wrote on Tue, 11 February 2014 15:40
That's so nice of you to point out my mistake. But what is the mistake ,if you can point out will be really helpful.


It is in the code you didn't post.

Previous Topic: trigger when insert into select
Next Topic: UTL_MAIL
Goto Forum:
  


Current Time: Fri Apr 19 14:49:34 CDT 2024