SQL> create table t (x int );
Table created.
SQL>
SQL> create or replace
2 procedure my_proc is
3 x int;
4 begin
5 insert into t values (2);
6
7 x := 1/0;
8 exception
9 when others then raise;
10 end;
11 /
Procedure created.
SQL>
SQL> insert into t values (1);
1 row created.
SQL> exec my_proc;
BEGIN my_proc; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "MCDONAC.MY_PROC", line 8
ORA-06512: at line 1
SQL>
SQL> select * from t;
X
----------
1
1 row selected.
See how the failure of the procedure (with the raise) un-did the transaction work that the *procedure* had done, but left the "prior" transaction as it was before the procedure started.
Now let us put a rollback in there
SQL> create table t (x int );
Table created.
SQL>
SQL> create or replace
2 procedure my_proc is
3 x int;
4 begin
5 insert into t values (2);
6
7 x := 1/0;
8 exception
9 when others then rollback; raise;
10 end;
11 /
Procedure created.
SQL>
SQL> insert into t values (1);
1 row created.
SQL> exec my_proc;
BEGIN my_proc; END;
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "MCDONAC.MY_PROC", line 8
ORA-06512: at line 1
SQL>
SQL> select * from t;
no rows selected
That's a bad procedure because it changes things that it was not "entitled" to do.