Check the concept on the bus. The oracle lock mechanism is somewhat different from MSSQL. Take the time to sit down and test it.
Oracle uses the lock mechanism to provide data concurrency, consistency, and integrity between transactions. These operations are automatically executed without user intervention.
Scenario Simulation: multiple users concurrently modify a row of a data table. Here we will experiment with a B/S application. In a multi-user environment, use the following statement to modify the HR. EMPLOYEES table.
email ?, phone_number employee_id email phone_number ?
This statement ensures that the data of the employee ID being modified is not modified after the application is queried and displayed to the end user. In this way, the application avoids the problem that one user overwrites the changes made by another user, or
Time |
Session 1 |
Session 2 |
Explanation |
T0 |
last_name GHIMURO . |
|
In session 1, the hr1 user queries Hr. employees for the Himuro record And displays the employee_id (118 ), Email (GHIMURO), and phone number (515.127.4565) attributes. |
T1 |
|
last_name GHIMURO . |
In session 2, the hr2 user queries Hr. employees for the Himuro record And displays the employee_id (118 ), Email (GHIMURO), and phone number (515.127.4565) attributes. |
T2 |
phone_number employee_id email phone_number row updated. |
|
In session 1, the hr1 user updates Phone number in the row 515.555.1234, which acquires a lock on The GHIMURO row. |
T3 |
|
phone_number employee_id email phone_number |
In session 2, the hr2 user attempts Update the same row, but is blocked Because hr1 is currently processing Row. The attempted update by hr2 occurs Almost simultaneously with the hr1 Update. |
T4 |
COMMIT; Commit complete. |
|
In session 1, the hr1 user commits Transaction. The commit makes the change Himuro permanent and unblocks Session 2, which has been waiting. |
T5 |
|
0 rows updated. |
The GHIMURO row was modified in such Way that it no longer matches its Predicate. Because the predicates do not match, Session 2 updates no records. |
T6 |
phone_number employee_id email phone_number row updated. |
|
In session 1, the hr1 user realizes that it Updated the GHIMURO row with Wrong phone number. The user starts New transaction and updates the phone Number in the row to 515.555.1235, Which locks the GHIMURO row. |
T7 |
|
last_name GHIMURO . |
In session 2, the hr2 user queries Hr. employees for the Himuro record. The record shows the phone number Update committed by session 1 at t4. Oracle Database read consistency Ensures that session 2 does not see Uncommitted change made at t6. |
T8 |
|
phone_number employee_id email phone_number |
In session 2, the hr2 user attempts Update the same row, but is blocked Because hr1 is currently processing Row. |
T9 |
ROLLBACK; Rollback complete. |
|
In session 1, the hr1 user rolls back Transaction, which ends it. |
T10 |
|
1 row updated. |
In session 2, the update of the phone Number succeeds because the session 1 Update was rolled back. The GHIMURO Row matches its predicate, so the update Succeeds. |
T11 |
|
COMMIT; Commit complete. |
Session 2 commits the update, ending The transaction. |
At the t2, t3, t4, and t5 moments, it is clear that session2's modification to the employee is invalid, avoiding lost update.