Solved

PLSQL Question

Posted on 2013-06-29
7
126 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

'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 …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
Via a live example, show how to take different types of Oracle backups using RMAN.

896 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

12 Experts available now in Live!

Get 1:1 Help Now