Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Exception IN Oracle Procedure

Posted on 2008-10-20
5
Medium Priority
?
631 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
[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
  • 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

688 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