Hi,
Please see below :-
SQL> create table t (x int);
Table created.
SQL> insert into t values (1);
1 row created.
SQL> alter session set isolation_level=serializable;
ERROR:
ORA-01453: SET TRANSACTION must be first statement of transaction
SQL> exec dbms_stats.gather_table_stats( user, 'T' );
PL/SQL procedure successfully completed.
SQL> alter session set isolation_level=serializable;
Session altered.
Why did the alter session statement throw error before gathering stats and not after it ?
It's nothing to do with gather stats directly - it is because you cannot the the isolation level if you have a currently active transaction. eg
SQL> create table t (x int);
Table created.
SQL> insert into t values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> alter session set isolation_level=serializable;
Session altered.
The gather_stats call did a commit, which is why the alter session worked after that.