Oracle数据库事务、重做日志与撤销日志详解
自主事务的工作原理
自主事务是Oracle数据库中一个重要的概念,通过示例能更好地理解其行为和后果。
1. 创建测试表
sql EODA@ORA12CR1> create table t ( msg varchar2(25) ); Table created.
此表用于存储消息,作为后续操作的基础。
2. 创建存储过程
- 自主事务存储过程 Autonomous_Insert
sql EODA@ORA12CR1> create or replace procedure Autonomous_Insert 2 as 3 pragma autonomous_transaction; 4 begin 5 insert into t values ( 'Autonomous Insert' ); 6 commit; 7 end; 8 / Procedure created.
这里使用 pragma autonomous_transaction
指令,告知数据库该过程执行时作为一个新的自主事务,独立于其父事务。
- 非自主事务存储过程 NonAutonomous_Insert
sql EODA@ORA12CR1> create or replace procedur