1.閃回事務處理功能的前提
sql> show user;
user is "sys"
sql> alter database add supplemental log data;
database altered.
sql> alter database add supplemental log data(primary key) columns;
database altered.
sql> grant execute on dbms_flashback to scott;
grant succeeded.
sql> grant select any transaction to scott;
grant succeeded.
2.建立一張實驗表
sql> create table t (id number,name varchar2(10));
table created.
第乙個事務,插入兩行,提交
sql> insert into t values(1,'a');
1 row created.
sql> insert into t values(2,'b');
1 row created.
sql> commit;
commit complete.
第二事務,插入5行,提交
sql> insert into t values(3,'c');
1 row created.
sql> insert into t values(3,'c');
1 row created.
sql> insert into t values(3,'c');
1 row created.
sql> insert into t values(3,'c');
1 row created.
sql> insert into t values(3,'c');
1 row created.
sql> commit;
commit complete.
執行乙個閃回版本查詢
sql>select versions_starttime,versions_endtime,versions_startscn,
versions_endscn,versions_xid,versions_operation from scott.t1
versions between scn minvalue and maxvalue order by 1;
versions_starttime versions_endtime versions_startscn versions_endscn versions_xid v
30-may-16 02.44.39 pm 30-may-16 02.55.33 pm 1040502 1042027 02000500b2020000 i
30-may-16 02.44.39 pm 30-may-16 02.55.33 pm 1040502 1042027 02000500b2020000 i
30-may-16 02.45.15 pm 1040522 01001f00fc010000 i
30-may-16 02.45.15 pm 1040522 01001f00fc010000 i
30-may-16 02.45.15 pm 1040522 01001f00fc010000 i
30-may-16 02.45.15 pm 1040522 01001f00fc010000 i
30-may-16 02.45.15 pm 1040522 01001f00fc010000 i
30-may-16 02.55.33 pm 1042027 01002100fc010000 d
30-may-16 02.55.33 pm 1042027 01002100fc010000 d
3.執行閃回事務查詢
閃回事務查詢,可以看到,一共兩個事務,乙個事務包含兩條dml,乙個事務包含五條dml
通過undo_sql欄位給出反sql
我們可以手動的取消某乙個事務
但是,當事務比較複雜,事務中包含dml較多的情況下
手動去執行閃回事務處理,將變得困難,且容易出錯
資料庫提供了dbms_flashback.transaction_backout函式
幫助我們自動的,去執行同乙個事務下,所有反sql
能夠保障事務的完整性
sql> select xid,operation,undo_sql
2 from flashback_transaction_query
3 where table_name='t';
xid operation undo_sql
01000200ed010000 insert delete from "scott"."t" where rowid = 'aaaso5aaeaa
aaiuaab';
01000200ed010000 insert delete from "scott"."t" where rowid = 'aaaso5aaeaa
aaiuaaa';
06000b00af020000 insert delete from "scott"."t" where rowid = 'aaaso5aaeaa
aaiuaag';
06000b00af020000 insert delete from "scott"."t" where rowid = 'aaaso5aaeaa
aaiuaaf';
06000b00af020000 insert delete from "scott"."t" where rowid = 'aaaso5aaeaa
aaiuaae';
06000b00af020000 insert delete from "scott"."t" where rowid = 'aaaso5aaeaa
aaiuaad';
06000b00af020000 insert delete from "scott"."t" where rowid = 'aaaso5aaeaa
aaiuaac';
7 rows selected.
4.執行閃回事務處理
閃回事務處理需要sys使用者去執行
sql> show user;
user is "sys"
sql> declare
2 v_xid sys.xid_array;
3 begin
4 v_xid := sys.xid_array('01000200ed010000');
5 dbms_flashback.transaction_backout(1,v_xid);
6 end;
7 /pl/sql procedure successfully completed.
在當前會話,查詢閃回之後的結果,因為此時該事務未提交,所以別的會話看不到閃回後的結果
在確認,閃回達到預期之後,提交
sql> select * from scott.t;
id name
3 c3 c
3 c3 c
3 csql> commit;
commit complete.
回到scott進行確認
sql> select * from t;
id name
3 c3 c
3 c3 c
3 c
PB事務處理
1 資料視窗更新,只要dberror有錯誤,而事先沒有做過任何commit工作,那麼rollback可以回滾到上次commit位置,即上次commit後所有的資料將被回滾。2 如果是直接寫入sql語句,只要資料庫出現錯誤,那麼rollback可以回滾到上次commit的位置,即上次commit後所有...
MySQL事務處理
start transaction,commit和rollback語法 start transaction begin work commit work and no chain no release rollback work and no chain no release set autocom...
ASP事務處理
asp事務處理。測試資料庫為sql server,伺服器為本機,資料庫名為test,表名為a,兩個欄位id int 主鍵標識,num int set conn server.createobject adodb.connection strconn provider sqloledb.1 persi...