Solved

PLSQL Question

Posted on 2013-06-29
7
125 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
  • 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 22

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now