Basic Oracle Concepts and Programming Question:
Download Job Interview Questions and Answers PDF
How To Experiment a Data Lock in Oracle?
Answers:
Answer #1If you want to have some experience with data locks, you can create two windows runing two SQL*Plus sessions. In session 1, you can run a UPDATE statements to create a data lock. Before committing session 2, switch to session 2, and run a UPDATE statements on the same row as session 1. The UPDATE statement will be put into wait status because of the data lock. Follow the tutorial exercise below to experience yourself:
(session 1)
SQL> connect HR/globalguideline
SQL> SET TRANSACTION
ISOLATION LEVEL
READ COMMITTED;
Transaction set.
SQL> SELECT * FROM ggl_links;
ID URL NOTES
--- ---------------- --------
101 globalguideline.COM
110 globalguideline.COM
SQL> UPDATE ggl_links
SET url='globalguideline.com'
WHERE id=101;
1 row updated.
(lock created on row id=101)
(session 1)
SQL> connect HR/globalguideline
SQL> SET TRANSACTION
ISOLATION LEVEL
READ COMMITTED;
Transaction set.
SQL> SELECT * FROM ggl_links;
ID URL NOTES
--- ---------------- --------
101 globalguideline.COM
110 globalguideline.COM
SQL> UPDATE ggl_links
SET url='globalguideline.com'
WHERE id=101;
1 row updated.
(lock created on row id=101)
Answer #2(session 2)
SQL> connect HR/globalguideline
SQL> SET TRANSACTION
ISOLATION LEVEL
READ COMMITTED;
Transaction set.
SQL> UPDATE ggl_links SET
notes='FAQ Resource'
WHERE id=101;
(wait on lock at id=101)
SQL> COMMIT;
(lock on row id=101 released)
(ready to run UPDATE)
1 row updated.
SQL> SELECT * FROM ggl_links;
ID URL NOTES
--- ---------------- --------
101 globalguideline.com
110 globalguideline.COM
SQL> COMMIT;
SQL> SELECT * FROM ggl_links;
ID URL NOTES
--- ---------------- ------------
101 globalguideline.com FAQ Resource
110 globalguideline.COM
SQL> connect HR/globalguideline
SQL> SET TRANSACTION
ISOLATION LEVEL
READ COMMITTED;
Transaction set.
SQL> UPDATE ggl_links SET
notes='FAQ Resource'
WHERE id=101;
(wait on lock at id=101)
SQL> COMMIT;
(lock on row id=101 released)
(ready to run UPDATE)
1 row updated.
SQL> SELECT * FROM ggl_links;
ID URL NOTES
--- ---------------- --------
101 globalguideline.com
110 globalguideline.COM
SQL> COMMIT;
SQL> SELECT * FROM ggl_links;
ID URL NOTES
--- ---------------- ------------
101 globalguideline.com FAQ Resource
110 globalguideline.COM
Download Oracle Database Interview Questions And Answers
PDF
Previous Question | Next Question |
How Data Locks Are Respected in Oracle? | How To View Existing Locks on the Database? |