Solved

Exception IN Oracle Procedure

Posted on 2008-10-20
5
628 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 200 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 300 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 300 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

762 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