Purpose
You can use this statement to set the transaction isolation level.
OceanBase Database supports two isolation levels in MySQL mode: read committed and repeatable read. The default isolation level is read committed.
You cannot set the isolation level during transaction execution. Otherwise, an error is returned.
ERROR:ORA-01453: SET TRANSACTION must be first statement of transactionYou need to make sure that Global Timestamp Service (GTS) is enabled before you enable the serializable isolation level.
When you run session transactions, you need to set the isolation level to the session level. This isolation level can be overridden by isolation levels at the transaction level.
Syntax
SET [GLOBAL | SESSION | LOCAL] TRANSACTION trans_opt;
trans_opt:
transaction_access_mode
| isolation_level
| transaction_access_mode, isolation_level
| isolation_level, transaction_access_mode
transaction_access_mode:
[READ ONLY | READ WRITE]
isolation_level:
ISOLATION LEVEL {
READ UNCOMMITED
| READ COMMITED
| REPEATABLE READ
| SERIALIZABLE
}
Parameters
| Parameter | Description |
|---|---|
| GLOBAL | SESSION | LOCAL | The effective scope of the transaction isolation level. This parameter is unspecified by default.
|
| READ ONLY | READ WRITE | The read/write mode of the transaction. |
| READ UNCOMMITED | Specifies that the transaction isolation level is read uncommitted. Note: The current version does not support the read uncommitted isolation level. |
| READ COMMITED | Specifies that the transaction isolation level is read committed. |
| REPEATABLE READ | Specifies that the transaction isolation level is repeatable read. |
| SERIALIZABLE | Specifies that the transaction isolation level is serializable. Note: OceanBase Database does not support the serializable isolation level for the sys tenant because GTS cannot be enabled for the sys tenant. |
Examples
Set the transaction isolation level of the next transaction in the current session to read committed.
obclient> SET TRANSACTION ISOLATION LEVEL READ COMMITTED;Set the transaction isolation level of the current session to repeatable read.
obclient> SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;