Oracle 18C新特性:ALTER SYSTEM CANCEL SQL

zhangchaoming 2020-03-05

介绍

18c官方文档《Database Administrator’s Guide》中有介绍,关于取消会话的sql事务有新增特性,可以使用ALTER SYSTEM CANCEL SQL。。对事务取消,具体使用方法如下: 

Oracle 18C新特性:ALTER SYSTEM CANCEL SQL

实践证明

##session 1
SQL> select sid, serial# from v$session where sid = userenv(‘SID‘);
       SID    SERIAL#
---------- ----------
        25      29476
SQL> create table t_source as select * from dba_source where 1=2;
Table created.
SQL> select count(*) from t_source;
  COUNT(*)
----------
         0
SQL>  insert into t_source select * from dba_source;
292640 rows created.                  <========================== 备注此时的总记录数
SQL>  insert into t_source select * from dba_source;

正在执行第2次insert时,在另外一个session执行取消操作。

##session 2
SQL> alter system cancel sql ‘25,29476‘;
System altered.

检查session 1 此时的执行信息。

##session 1
SQL>  insert into t_source select * from dba_source;
 insert into t_source select * from dba_source
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation

SQL> select count(*) from t_source;

  COUNT(*)
----------
    292640                         <========================== 记录数和第2次插入之前一样

这里可以看到第2次插入的记录已经回滚。

相关推荐