Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PL SQL transaction question

774666May 23 2010 — edited May 24 2010
I'm a pl/sql noob.

I'm messing around with different aspects of pl sql to get my head around it and decided to try to do a transactional delete across a number of tables; if one doesn't work, all roll back. Hit upon an issue.

I have intentionally set up a foreign key exception in my db so that I could see my fk exception was handled. I get an error (included underneath the plsql code) saying I didn't set up a save point. I can't see how, logically, this can be the case.

Is there something I'm doing wrong, or that I'm over looking. Is there an autocomit in oracle/plsql that is mucking this up.

Any help appreciated :o)

for i in 1..firsttab.count
loop
BEGIN
SAVEPOINT onetask;


a:=firsttab(i).a;
b:=firsttab(i).b;
c:=firsttab(i).c;


delete from table1 where t_=b;
delete fromtable2 where pi_=a;
delete from table3 where t_=b;
delete from table4 where pi_=a;
update table5 set pi_=null where id_=b;
update table6 set t_=null where id_=a;
delete from table5 where t_=a;
delete from table6 where pi_=a;
removed:=removed+1;

exception when others then
if sqlcode = -02292 then
dbms.out("don't worry about this line, it has correct syntax in actual code);
end if;
ROLLBACK TO SAVEPOINT onetask;
end;




Error report:
ORA-01086: savepoint 'ONETASK' never established
ORA-02292: integrity constraint (APP.FK_T_PI) violated - child record found
ORA-06512: at "APP.DESTROY_JBPM", line 120
ORA-06512: at line 2
01086. 00000 - "savepoint '%s' never established"
*Cause: Trying to roll back to a save point that was never established.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2010
Added on May 23 2010
10 comments
1,940 views