Oracle | Transaction
1. What Is a Transaction?
A transaction is a logical unit of work requested by a user to be applied to the database objects. Oracle server introduces the transaction concept to allow users to group one or more SQL statements into a single transaction, so that the effects of all the SQL statements in a transaction can be either all committed (applied to the database) or all rolled back (undone from the database).
2. How To Start a New Transaction?
There is no SQL statement to explicitly start a new transaction. Oracle server implicitly starts a new transaction with the following two conditions:
(1) The first executable statement of a new user session will automatically start a new transaction.
(2) The first executable statement after a previous transaction has been ended will automatically start a new transaction.
3. What Is a READ WRITE Transaction?
A READ WRITE transaction is a transaction in which the read consistency is set at the statement level. In a READ WRITE transaction, a logical snapshot of the database is created at the beginning of the execution of each statement and released at the end of the execution. This guaranties that all reads within a single statement get consistent data from the database.
For example, if you have a query statement that takes 10 minutes to be executed, a snapshot of the database will be created for this statement for 10 minutes. If a subquery is used in this statement, it will get the consistent data no matter when it gets executed within this 10 minutes. In another word, data changes made during this 10 minutes by other users will not impact the execution of this query statement.
By default, all transactions are started as READ WRITE transactions
4. What Is a READ ONLY Transaction?
A READ ONLY transaction is a transaction in which the read consistency is set at the transaction level. In a READ ONLY transaction, a logical snapshot of the database is created at the beginning of the transaction and released at the end of the transaction. This guaranties that all reads in all statements within this transaction get consistent data from the database.
For example, if you have a transaction with many statements that takes 10 hours to be executed, a snapshot of the database will be created for this transaction for 10 hours. If a query statement is executed at the beginning of the transaction and at the end of the transaction, it will return the same result guarantied. In another word, data changes made during this 10 hours by other users will not impact the execution of statements within this transaction.
浙公网安备 33010602011771号