Solved

Roll back with trigger

Posted on 2001-07-16
5
1,917 Views
Last Modified: 2010-01-18
How can I execute a Rollback statement with the use of a trigger? I know that I can not place a rollback statemnet in a trigger but how can I work around this obstacle.
0
Comment
Question by:rkm123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:ser6398
ID: 6287392
An unhandled exception in a trigger automatically rolls back the trigger body and the triggering statement.  If a predefined or user-defined error condition or exception is raised during the execution of a trigger
body, then all effects of the trigger body, as well as the triggering statement, are rolled back (unless
the error is trapped by an exception handler (use RAISE_APPLICATION_ERROR if handled)). Therefore, a trigger body can prevent the execution of the triggering statement by raising an exception. User-defined exceptions are commonly used in triggers that enforce complex security or constraints.  ONLY the triggering statement is rolled back => a commit saves any SQL made before that statement.

So, if you want to rollback, you can do something like:

declare
  ex_my_exception   EXCEPTION;
begin
  IF (user = 'BOB')
  THEN RAISE ex_my_exception;
  ELSE do_something_else;
  END IF;
end;

If you don't handle the exception, it will cause a rollback.
0
 
LVL 5

Accepted Solution

by:
ser6398 earned 20 total points
ID: 6287413
By the way, if you don't want the trigger to rollback the initiating statement, you can use PRAGMA AUTONOMOUS_TRANSACTION to make the trigger function within it's own transaction, so you can rollback only the trigger body, and not the initiating statement:

CREATE OR REPLACE TRIGGER ins_emp
   AFTER INSERT
   ON emp
 FOR EACH ROW
DECLARE
   PRAGMA AUTONOMOUS_TRANSACTION;
   vsal   NUMBER;
BEGIN
   ...

0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7038131
Please update and finalize this old, open question. Please:

1) Award points ... if you need Moderator assistance to split points, comment here with details please or advise us in Community Support with a zero point question and this question link.
2) Ask us to delete it if it has no value to you or others
3) Ask for a refund so that we can move it to our PAQ at zero points if it did not help you but may help others.

EXPERT INPUT WITH CLOSING RECOMMENDATIONS IS APPRECIATED IF ASKER DOES NOT RESPOND.

Thanks,

** Mindphaser - Community Support Moderator **

P.S.  Click your Member Profile, choose View Question History to go through all your open and locked questions to update them.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7053174
Recommended disposition:

    Accept ser6398's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7054295
Thanks, Dan.
I finalized this today and will monitor it in the event an adjustment is needed.
Moondancer - EE Moderator
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question