just wondering if we really need rollback/savepoint required inside a LOOP statement if we have exception catch inside.
create table my_Tab
(id number,
name varchar2(10),
address varchar2(100));
insert into my_tab values (1,'ABC','XXX');
insert into my_tab values (2,'DEF','YYY');
insert into my_tab values (3,'GHI','ZZZ');
insert into my_tab values (4,'JKL',null);
DECLARE
CURSOR cur_my_tab is
select * from my_tab;
l_var varchar2(100);
l_count number := 0;
begin
for rec_my_tab in cur_my_tab
loop
BEGIN
dbms_output.put_line('id' || rec_my_tab.id);
--savepoint sv_cur_my_tab;
dbms_output.put_line('name' || rec_my_tab.name);
select rec_my_tab.address into l_var from dual;
update my_Tab set id = id +4 where id = rec_my_tab.id;
dbms_output.put_line(l_var);
if rec_my_tab.address ='xxx' then
l_count:= rec_my_tab.id/l_count;
END IF;
Exception
when others then
dbms_output.put_line('in inner exception');
--rollback to sv_cur_my_tab;*/
end;
end loop;
Exception
when others then
dbms_output.put_line('in outer exception');
--rollback to sv_cur_my_tab;
end;
I have 2 queries wrt above query.
- When does the commit happen in the above sequence.
- in the above code consider the exception is thrown in the middle of the cursor (like 3rd or 4th iteration). will adding rollback & savepoint make a change in this? currently, the entire loop is completed and all updates are getting committed as well.