自治事务在 Oracle 中有自己的会话吗?
Do autonomous transactions have their own session in Oracle?
我有一个问题,可能是由于分布式事务。在手册中说:
When the first insert, update, or delete operation on a spatial table
(one with a spatial index) is performed in a distributed transaction,
all subsequent insert, update, or delete operations on the table, as
well as any prepare to commit operation (the first branch to prepare a
commit), in the transaction should happen in the same session as the
first operation.
由于我在进行自主交易,我想知道它们是否发生在同一个会话中,或者是否为它们打开了一个单独的会话。
感谢您的帮助
一个会话可以有多个事务,所以这一切都在一个会话中完成。
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
我有一个问题,可能是由于分布式事务。在手册中说:
When the first insert, update, or delete operation on a spatial table (one with a spatial index) is performed in a distributed transaction, all subsequent insert, update, or delete operations on the table, as well as any prepare to commit operation (the first branch to prepare a commit), in the transaction should happen in the same session as the first operation.
由于我在进行自主交易,我想知道它们是否发生在同一个会话中,或者是否为它们打开了一个单独的会话。
感谢您的帮助
一个会话可以有多个事务,所以这一切都在一个会话中完成。
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