[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PLSQL Question

Posted on 2013-06-29
7
Medium Priority
?
133 Views
Last Modified: 2014-05-27
I have to insert into data into five tables record by record. If in one of the insert the record is going to exception block then I have to do roll back to save point.
When I am using this functionality it is getting rollback for that table but it is continuing execution and inserting data in other tables.
My requirement is if one record goes in exception block that particular record should not be inserted into any of the other tables(record should be skipped) and continue with next record.
ALso, rollback should happen to only that record not all the records.

Any help would be appreciated.

Thanks.
0
Comment
Question by:pp89
[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
  • 2
7 Comments
 
LVL 5

Expert Comment

by:DOSLover
ID: 39287653
Using transaction control with SAVEPOINT might help you to achieve what you are trying to do. For example,
BEGIN
  SAVEPOINT start_tran;
  INSERT INTO ... first_table ;
   INSERT INTO ... second_table ;
  INSERT INTO ... third_table;
 INSERT INTO ... fourth_table ;
 INSERT INTO ... fifth_table ;
  EXCEPTION
  WHEN OTHERS THEN
    ROLLBACK TO start_tran;
    RAISE;
END;

Open in new window

0
 

Author Comment

by:pp89
ID: 39287672
I have nested loops that I am using in code. In exception block when I say rollback to save point it continues with other for loop and inserts into remaining loops.
But my requirement is rollback should happen completely for that record.
Thanks for your help.
0
 
LVL 5

Expert Comment

by:DOSLover
ID: 39288127
Since I don't see the code, I think the issue is the code is not  properly exiting the loop(s) after a rollback an exception occurs. Do you label the Loops that can be used to properly exit? Please see if this link can help (under section "Labeling a PL/SQL Loop"):
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/controlstructures.htm
0
Industry Leaders: 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!

 

Author Comment

by:pp89
ID: 39288344
One question here, if I write rollback to savepoint in exception section then that insert in that loop will be performed rollback but it will continue with other loops insert?
0
 

Accepted Solution

by:
pp89 earned 0 total points
ID: 39318010
I have used raise in the block and it works. Thanks All..
0
 
LVL 23

Expert Comment

by:Steve Wales
ID: 40092466
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
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.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

656 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