[20200512]oracle的事務隔離級別.txt
[20200512]oracle的事務隔離級別.txt
--//別人問的問題,我自己的工作也很少涉及這方面問題.我記憶最深的一次,開發要我匯出一部分資料回去改程式.
--//由於匯出時沒有加入flashscn引數,造成對方匯入時主外來鍵不一致,無法匯入.
--//參考APress Oracle Core Essential Internals for DBAs and Developers.pdf P18頁:
ISOLATION LEVELS
Oracle offers three isolation levels: read committed (the default), read only, and serializable. As a brief
sketch of the differences, consider the following scenario: table t1 holds one row, and table t2 is identical
to t1 in structure. We have two sessions that go through the following steps in order:
1. Session 1: select from t1;
2. Session 2: insert into t1 select * from t1;
3. Session 2: commit;
4. Session 1: select from t1;
5. Session 1: insert into t2 select * from t1;
If session 1 is operating at isolation level read committed, it will select one row on the first select, select
two rows on the second select, and insert two rows.
If session 1 is operating at isolation level read only, it will select one row on the first select, select one row
on the second select, and fail with Oracle error "ORA-01456: may not perform insert/delete/update operation inside a
READ ONLY transaction."
If session 1 is operating at isolation level serializable, it will select one row on the first select, select one
row on the second select, and insert one row.
--//正好3種方式的結果不一樣,重複測試做1個記錄.
1.環境:
SCOTT@test01p> @ ver1
PORT_STRING VERSION BANNER CON_ID
------------------------------ -------------- -------------------------------------------------------------------------------- ----------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
create table t1 as select rownum id from dual;
create table t2 as select * from t1 where 1=0;
--//分析略.
2.read committed:
--//也就是基本預設模式,平時工作中遇到不部分是這種模式:
--//sesion 1:
SCOTT@test01p> alter session set isolation_level=read committed;
Session altered.
SCOTT@test01p> select * from t1;
ID
---
1
--//sesion 2:
SCOTT@test01p> insert into t1 select * from t1;
1 row created.
SCOTT@test01p> commit;
Commit complete.
--//session 1:
SCOTT@test01p> select * from t1;
ID
---
1
1
SCOTT@test01p> insert into t2 select * from t1;
2 rows created.
--//If session 1 is operating at isolation level read committed, it will select one row on the first select, select
--//two rows on the second select, and insert two rows.
3.read only:
--//注:測試前還原建表時狀態.
--//sesion 1:
SCOTT@test01p> alter session set isolation_level=read only;
alter session set isolation_level=read only
*
ERROR at line 1:
ORA-02183: valid options: ISOLATION_LEVEL { SERIALIZABLE | READ COMMITTED }
--//不支援這樣設定read only。
SCOTT@test01p> set transaction read only;
Transaction set.
SCOTT@test01p> select * from t1;
ID
---
1
--//sesion 2:
SCOTT@test01p> insert into t1 select * from t1;
1 row created.
SCOTT@test01p> commit;
Commit complete.
--//session 1:
SCOTT@test01p> select * from t1;
ID
----------
1
SCOTT@test01p> insert into t2 select * from t1;
insert into t2 select * from t1
*
ERROR at line 1:
ORA-01456: may not perform insert/delete/update operation inside a READ ONLY transaction
--//If session 1 is operating at isolation level read only, it will select one row on the first select, select one row
--//on the second select, and fail with Oracle error "ORA-01456: may not perform insert/delete/update operation inside a
--//READ ONLY transaction."
4.serializable
--//注:測試前還原建表時狀態.
--//sesion 1:
SCOTT@test01p> alter session set isolation_level=serializable;
Session altered.
SCOTT@test01p> select * from t1;
ID
---
1
--//sesion 2:
SCOTT@test01p> insert into t1 select * from t1;
1 row created.
SCOTT@test01p> commit ;
Commit complete.
--//session 1:
SCOTT@test01p> select * from t1;
ID
---
1
SCOTT@test01p> insert into t2 select * from t1;
1 row created.
--//If session 1 is operating at isolation level serializable, it will select one row on the first select, select one
--//row on the second select, and insert one row.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2691669/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL事務的隔離級別MySql
- MySQL的事務隔離級別MySql
- MySQL事務隔離級別MySql
- 事務、特性、隔離級別
- MySQL 事務隔離級別MySql
- [Mysql]事務/隔離級別MySql
- PostgreSQL事務隔離級別SQL
- oracle事務隔離級別transaction isolation level初識Oracle
- 事務的四種隔離級別
- 理解mysql的事務隔離級別MySql
- 事務系統的隔離級別
- 事務的隔離級別與MVCCMVC
- 事務四種隔離級別
- 理解MySQL事務隔離級別MySql
- SqlServer事務詳解(事務隔離性和隔離級別詳解)SQLServer
- 資料庫事務與事務的隔離級別資料庫
- (轉)事務的四種隔離級別
- MySQL 的四種事務隔離級別MySql
- MySQL 事務的隔離級別初窺MySql
- MySQL事務隔離級別和MVCCMySqlMVC
- 事務ACID特性與隔離級別
- 啥是 MySQL 事務隔離級別?MySql
- mysql如何修改事務隔離級別MySql
- mysql事務隔離級別和鎖MySql
- Mysql鎖與事務隔離級別MySql
- Mysql 四種事務隔離級別MySql
- MySQL的事務處理及隔離級別MySql
- 聊聊資料庫的事務隔離級別資料庫
- 徹底搞懂 MySQL 事務的隔離級別MySql
- MySQL的事務隔離級別是什麼?MySql
- 資料庫事務與隔離級別資料庫
- 事務隔離級別(圖文詳解)
- 事務基礎特性及隔離級別
- MySQL 事務隔離級別實現原理MySql
- CYmysql事務隔離級別詳情dbzMySql
- oracle不同的事務transaction隔離級別isolation level進一步理解Oracle
- 事務的四大特性,以及隔離級別
- [資料庫]事務的4種隔離級別資料庫