【问题标题】:Do autonomous transactions have their own session in Oracle?自治事务在 Oracle 中有自己的会话吗?
【发布时间】:2021-10-13 02:49:24
【问题描述】:

我有一个问题,可能是由于分布式事务。在手册中它说:

当对空间表进行第一次插入、更新或删除操作时 (具有空间索引的)在分布式事务中执行, 对表的所有后续插入、更新或删除操作,如 以及任何准备提交操作(准备一个 提交),在事务中应该发生在同一个会话中 第一次操作。

由于我正在执行自主事务,我想知道它们是否发生在同一个会话中,或者是否为它们打开了一个单独的会话。

感谢您的帮助

【问题讨论】:

  • sys_context('USERENV', 'SID') 的值插入到某个表中并检查该值是否与主会话不同。

标签: oracle session transactions distributed


【解决方案1】:

一个会话可以有多个事务,所以这一切都在一个会话中完成。

SQL> create table t ( n number);

Table created.

SQL>
SQL> create or replace
  2  procedure p1 is
  3      pragma autonomous_transaction;
  4  begin
  5      insert into t values ( sys_context('userenv','sid'));
  6      commit;
  7  end;
  8  /

Procedure created.

SQL> create or replace
  2  procedure p2 is
  3      pragma autonomous_transaction;
  4  begin
  5      insert into t values ( sys_context('userenv','sid'));
  6      commit;
  7      p1;
  8  end;
  9  /

Procedure created.

SQL> create or replace
  2  procedure p3 is
  3      pragma autonomous_transaction;
  4  begin
  5      insert into t values ( sys_context('userenv','sid'));
  6      commit;
  7      p2;
  8  end;
  9  /

Procedure created.

SQL>
SQL> exec p3;

PL/SQL procedure successfully completed.

SQL> select * from t;

         N
----------
       982
       982
       982

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 2017-01-10
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多