drop table test_tab;
create table test_tab (x number, y varchar2(100));
declare
l_cnt number := 0;
begin
execute immediate 'truncate table test_tab';
insert into test_tab select level x, lpad('A', 90, 'B')||level from dual connect by level <= 500;
for c in (select x, y from test_tab) loop
l_cnt := l_cnt + 1;
dbms_output.put_line(c.x);
if c.x > 300 then
rollback;
end if;
end loop;
exception when others then
dbms_output.put_line('Row CNT = '||l_cnt);
raise;
end;
/
--------------- Test Output -----------------
310
311
312
313
Row CNT = 100
declare
*
ERROR at line 1:
ORA-01002: fetch out of sequence
ORA-06512: at line 17
ORA-06512: at line 7
ORA-06512: at line 7
For Temporary Table ORA-01002, see Blog: One Test on the Different Errors of Oracle Global Temporary Tables vs. Private Temporary Tables (https://ksun-oracle.blogspot.com/2024/01/one-test-on-different-errors-of-oracle.html)