Solved

Using ROLLBACK FUNCTION

Posted on 2011-02-10
13
486 Views
Last Modified: 2012-06-27
Hello,

I'm trying to ROLLBACK records after a delete and it appears that it not working as expected. I'm am inserting in approx 20 tables then deleting the records from the source tables. I am then running an IF statement and if the criteria is not meant (or an error occurs) then rollback.

Do you have any ideas?

Thanks
0
Comment
Question by:lulubell-b
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34864843
Define: "not working as expected".

Rollback will 'undo' all non-commited transactions.  Are you doing intermittent commits?
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34864890
are you simply waiting for the rollback to complete?

you can monitor the amount of rollback used per transaction and extrapolate how long it might take to complete


SELECT d.tablespace_name,r.NAME,s.username, s.SID,s.serial#,p.spid os_pid , t.addr,t.used_ublk
FROM v$transaction t, v$rollname r, v$session s,v$process p,dba_rollback_segs d
WHERE t.addr = s.taddr
AND p.addr = s.paddr
AND t.xidusn = r.usn
AND d.segment_name = r.NAME
ORDER BY d.tablespace_name,r.NAME,s.username;
0
 

Author Comment

by:lulubell-b
ID: 34865094
I don't think so, I ran my procedure with the rollback imbedded and then looking at the table No data was rolled back. I'm confused, it works when I remove the delete statements, but doesnt seem to work when I add the delete statments back into the PL/SQL.
0
 

Author Comment

by:lulubell-b
ID: 34865098
What are intermittent commits? I'm unsure.
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 333 total points
ID: 34865111
these would be intermittent commits,  

delete yourtable where id = 1;
commit;
delete yourtable where id = 2;
commit;
delete yourtable where id = 3;
commit;
delete yourtable where id = 4;
commit;

rollback;  -- this won't do anything

the commits could be in a loop too, they don't have to spaced literally between sql statements like that


0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34865119
are you doing any DDL?  alter/create/drop/truncate, etc?  DDL  does an implicit commit
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.

 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 167 total points
ID: 34865166
Look through all the code.  I bet different functions/procedures/pieces of it are doing commits that you don't know about.
0
 

Author Comment

by:lulubell-b
ID: 34865306
Within my procedure I'm doing

INSERTs
DELETE
THEN CALLING ANOTHER PROCEDURE WHICH IS SELECTING AND RETURN A VALUE.

I'm confused.

0
 
LVL 14

Expert Comment

by:ajexpert
ID: 34865308
Do you have COMMIT at any point in your procedure?

Possiblity is that your logic met all the CRITERIA written in IF condition so it didnt rollback
0
 

Author Comment

by:lulubell-b
ID: 34865445
I do not have any commits in the procedures and I'm positive that the value is returning correctly from the second procedure.
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34865464
can you post the code? and sample data/results that demonstrate the problem ?

the symptoms you describe and the mini-pseudocode snippets don't coincide
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 333 total points
ID: 34865477
and remember, the word "commit" doesn't need to be in the code.

any DDL statement will commit for you.

and some built in packages will commit for you too
0
 

Author Comment

by:lulubell-b
ID: 34973092
Thank you, still unsure why the rollback isn't working correctly. I will revisit later. Thank you
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

867 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

16 Experts available now in Live!

Get 1:1 Help Now