Solved

PLSQL Question

Posted on 2013-06-29
7
127 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
exp/imp 25 73
Retreiving column names in Windows but not in Unix 11 45
How To Convert Date Stored as Varchar as an MSSQL DATE Type Field In a VIEW 3 22
Sql Server group by 10 27
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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 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.

770 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