Solved

PLSQL Question

Posted on 2013-06-29
7
130 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
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!

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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.

733 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