Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Exception IN Oracle Procedure

Posted on 2008-10-20
5
Medium Priority
?
632 Views
Last Modified: 2013-12-18
If there is an exception in Oracle procedure, will it roll back or do i have to roll back explicitly?

create or replace PROCEDURE Proc()

 

IS

BEGIN

  UPDATE STMT;

  EXCEPTION

  WHEN OTHERS THEN

      ROLLBACK;

END;
0
Comment
Question by:srikanthradix
  • 3
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 600 total points
ID: 22762064
an exception, per se makes that the statement itself is rolled back.
0
 
LVL 42

Assisted Solution

by:dqmq
dqmq earned 900 total points
ID: 22762072
>If there is an exception in Oracle procedure, will it roll back or do i have to roll back explicitly?

Depends on whether it is ultimately handled or not.  If the exception bubbles up to the highest level and the task aborts, then the rollback is implicit.  However, along the way, it bubbles up through an exception handler, then the rollback must be explicit.  

In other words, if on of your error handlers traps the error, then the choice to rollback or not is up to you.  In your example code, comment out the rollback statement and you do NOT get a rollback.  Comment out the entire exception block and you do.

Bottom line, if you want a rollback, always best to do it explicitly and remove all doubt.
0
 
LVL 42

Assisted Solution

by:dqmq
dqmq earned 900 total points
ID: 22762109
Consider that you may NOT want to rollback after an exception.  You have that option by trapping the exception and then escaping to the higher level block without issuing the rollback.
0
 

Author Closing Comment

by:srikanthradix
ID: 31508011
Thanks, Can you please also look at this question?
http://www.experts-exchange.com/Database/Oracle/PL_SQL/Q_23831929.html
0
 
LVL 42

Expert Comment

by:dqmq
ID: 22764196
I've responded to that question.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.‚Äč
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

885 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