IT Community - Software Programming, Web Development and Technical Support

Can we have a commit statement inside a trigger? if no why cant we?

This is a discussion on Can we have a commit statement inside a trigger? if no why cant we? within the Database Support forums, part of the Web Development category; Hi all, Could you explain commit statement inside a trigger? if no why cant we?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-11-2007, 02:48 AM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Sep 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Question Can we have a commit statement inside a trigger? if no why cant we?

Hi all,
Could you explain commit statement inside a trigger? if no why cant we?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-11-2007, 02:50 AM
Sundaram Sundaram is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Location: chennai
Posts: 117
Sundaram is on a distinguished road
Send a message via MSN to Sundaram Send a message via Yahoo to Sundaram
Default Re: Can we have a commit statement inside a trigger? if no why cant we?

b'cas trigger and porcedure can have the auto commit so that we can't use the commit statement inside the trigger
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-11-2007, 02:55 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default Re: Can we have a commit statement inside a trigger? if no why cant we?

Hi ramesh,

Yes ,You can Commit inside the trigger.

But for this you have to make this trigger transaction to be a Independent transaction from its parent transaction, You can do this by using Pragma. Pragma AUTONOMOUS_TRANSACTION allow you to build the Indepadent(child) Transaction,started by another. Shold be declare in DECLARE section of any subprogram.

Used to make Modular and Resuable Blocks. if you need the example then ask to me.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-11-2007, 02:58 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: Can we have a commit statement inside a trigger? if no why cant we?

Triggers should not contain transaction control statements like commit, rollback, savepoint r set transaction. Because it is firedas part of the execution of the triggering statement. When the triggering statement is committed or rolled back, work in the trigger is committed or rolled back as well.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-11-2007, 03:01 AM
Mramesh Mramesh is offline
D-Web Sr.Programmer
 
Join Date: Sep 2007
Location: Chennai
Posts: 106
Mramesh is on a distinguished road
Send a message via MSN to Mramesh
Default Re: Can we have a commit statement inside a trigger? if no why cant we?

Quote:
Originally Posted by a.deeban View Post
Hi ramesh,

Yes ,You can Commit inside the trigger.

But for this you have to make this trigger transaction to be a Independent transaction from its parent transaction, You can do this by using Pragma. Pragma AUTONOMOUS_TRANSACTION allow you to build the Indepadent(child) Transaction,started by another. Shold be declare in DECLARE section of any subprogram.

Used to make Modular and Resuable Blocks. if you need the example then ask to me.
Hello Deeban,

Can you give us example?

thanks,

Ramesh Kumar M
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-11-2007, 03:07 AM
SaravananJ SaravananJ is offline
D-Web Programmer
 
Join Date: Aug 2007
Posts: 79
SaravananJ is on a distinguished road
Default Re: Can we have a commit statement inside a trigger? if no why cant we?

u are saying that we can not use transaction control statement in trigger

bacause trigger is fired as part of execution of triggering statement which cause trigger is fired.when trigger statement is commited or rollback trigger transaction is commited or rollback as well.

then how by the use of pragma autonomous_transaction we can use commit,rollback etc

and here some one telling that by the use of pragma autonomous_transaction it is commited independent of parent transaction

so i want to know which statement is a parent transaction in the case of trigger?

is it is triggering statement?
__________________
J.Saravanan
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-11-2007, 03:08 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default Re: Can we have a commit statement inside a trigger? if no why cant we?

hi
try this one

Code:
CREATE OR REPLACE TRIGGER t_trigger
AFTER INSERT ON t1 FOR EACH ROW

DECLARE
  PRAGMA AUTONOMOUS_TRANSACTION;
 i PLS_INTEGER;
BEGIN
  SELECT COUNT(*)
  INTO i
  FROM t1;

  INSERT INTO t2
  VALUES
  (i);
  COMMIT;
END;
/
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run an exe from an oracle trigger H2o Database Support 5 08-09-2007 11:55 AM
Storing the output from trigger in a text file sureshbabu Database Support 3 07-27-2007 06:44 AM
How to enforce Transaction concept (ie: commit,rollback ) from .net web application kingmaker C# Programming 0 07-16-2007 11:15 PM
how to create trigger in MYSQL Jeyaseelansarc Database Support 5 07-10-2007 11:53 PM
how to retrieve the data after commit statement vadivelanvaidyanathan Database Support 3 03-21-2007 05:49 AM


All times are GMT -7. The time now is 04:25 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0