Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 11th, 2005, 09:40 AM
DBStudent DBStudent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 54 DBStudent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 1 m 34 sec
Reputation Power: 5
Commit in Oracle trigger??

Hi,

I want to achieve this:
If ATable has new record, fire the AFTER INSERT row level trigger. And inside the trigger will insert the ATable's primary key into BTable. Then inside trigger, wait for 120 seconds:

INSERT INTO BTable VALUES (:NEW.ATableKey);
DBMS_LOCK.SLEEP(120);

During this 120 period, i would like to let other table read the ATable primary key data in BTable. However, this fail because commit is not yet performed on BTable.

So, BTable will have no data until 120 seconds is over. So, i would like to commit the insertion to BTable in ATable's trigger. Is this possible?


Thanks,

Reply With Quote
  #2  
Old August 11th, 2005, 10:41 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,808 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 21 h 29 m 33 sec
Reputation Power: 278
With a simple:
sql Code:
Original - sql Code
  1. COMMIT;

But check if the triggers need an authonomous transaction or not.
For reference see this

Reply With Quote
  #3  
Old August 12th, 2005, 07:39 PM
michaeljshannon michaeljshannon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 26 michaeljshannon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 38 m 15 sec
Reputation Power: 0
While this may be technically possible, you might want to consider a different technique. Without knowing specifically what you are trying to accomplish, it is difficult to comment.

Just be very careful when using autonomous transactions and give special consideration to what happens if, for some reason, the insert trigger fails for Table A. The autonomous transaction is going to perform the commit, perhaps with bad or otherwise unusable data.

FYI

A common misuse of autonomous transactions is to eliminate mutating errors that occur when trying to perform a select on the same table that is being modified.

A common practical use is for creating log entries whether or not the calling commit fails.

Reply With Quote
  #4  
Old August 15th, 2005, 04:15 AM
DBStudent DBStudent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 54 DBStudent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 1 m 34 sec
Reputation Power: 5
Now i have another issue.....

I have two tables: TableA, TableB, TableC

TableB will keep track the TableA's primary key.

TableC will have AFTER INSERT row level trigger that will execute by checking th primary key of TableA in TableB.

I run these insert statements in one script:
INSERT INTO TableA VALUES (...);
COMMIT;

INSERT INTO TableC VALUES (...);
COMMIT;

Found that after insert statement executed on TableA,
it wait for 120 secs.

During 120 secs, yes, the TableB will have primary key of TableA. (using autonomous transaction)

But Then the TableC trigger is not being executed. Because TableC insert statement come after
TableA trigger.

When 120 secs is over, which is too late, because the TableA have finish execution.

I would like to achieve this:
While during 120 secs, insert the data into TableC.


Is this possible?


Thanks.

Reply With Quote
  #5  
Old August 18th, 2005, 05:36 PM
michaeljshannon michaeljshannon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 26 michaeljshannon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 38 m 15 sec
Reputation Power: 0
Without knowing EXACTLY what you are trying to accomplish, I will hazard a guess that you may want to reconsider this obviously error-prone method.

Consider this alternative ( again I may be off because of lack of information ).

It sounds like you could better accomplish your desired results using transactions.

Basically, you begin a transaction, perform one or more operations and end the transaction. The concept is to be able to "roll-back" at any point during the transaction should something fail.

If this is way off-base and you still need help, could you explain in words ( not syntax ) what you are trying to accomplish ?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Commit in Oracle trigger??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway