I do not understand your "transactional logic" at all - because the logic seems "really wrong"
do you understand what commit and rollback actually do?
and that databases ARE BORN TO JOIN
and that the logic above is really horrendous? I cannot imagine this is what you really intend.
here is your logic as it stands:
loop over rows randomly from t1
loop over rows randomly from t2 where t2.col1 = t1.col1
insert into t3;
if t2.col1 = '3'
then
ROLLBACK SET RANDOM SET OF ROWS WE JUST INSERTED - might
be every single row, might be some arbitrary set of rows
because sometimes we commit. But some UNKNOWN RANDOM SET OF ROWS
will be rolled back.
insert into error A SINGLE ROW (we just lost a bunch but we
log a single row
COMMIT;
end if;
end loop
end loop
COMMIT;basically, that is botched beyond repair.
If your last row you RANDOMLY HIT is a '3' record, you insert NOTHING into t3.
If on the other hand, the last row you RANDOMLY HIT is not a '3' record, you insert and commit into t3 all of the rows since the last time you RANDOMLY HIT a '3' record.
there is nothing good here. You are doing a do it yourself join (loops in loops) that is horrible. Your transactional logic makes no sense at all and leaves the database in sort of a random state after it is done.
How about you phrase your *requirement* in text...
oh, and tie it all back to "execute immediate and rollback segments" :)