Collections:
Set a READ ONLY Transaction in Oracle
How To Set a Transaction To Be READ ONLY in Oracle?
✍: FYIcenter.com
If you want a transaction to be set as READ ONLY, you need to the transaction with the SET TRANSACTION READ ONLY statement. Note that a DML statement will start the transaction automatically. So you have to issue the SET TRANSACTION statement before any DML statements. The tutorial exercise below shows you a good example of READ ONLY transaction:
SQL> connect HR/fyicenter SQL> SET TRANSACTION READ ONLY; Transaction set. SQL> SELECT * FROM fyi_links; ID URL NOTES COUNTS CREATED ------- ---------------- ---------- ---------- --------- 101 FYICENTER.COM 07-MAY-06 110 CENTERFYI.COM 07-MAY-06 112 oracle.com 07-MAY-06 113 sql.com 07-MAY-06
Keep the "HR" SQL*Plus window as is, and open another window to run another instance of SQL*Plus.
>cd (OracleXE home directory) >.\bin\sqlplus /nolog SQL> connect SYSTEM/password Connected. SQL> DELETE FROM hr.fyi_links where id = 112; 1 row deleted. SQL> DELETE FROM hr.fyi_links where id = 113; 1 row deleted. SQL> COMMIT; Commit complete.
Go back to the "HR" SQL*Plus window.
SQL> SELECT * FROM fyi_links; ID URL NOTES COUNTS CREATED ------- ---------------- ---------- ---------- --------- 101 FYICENTER.COM 07-MAY-06 110 CENTERFYI.COM 07-MAY-06 112 oracle.com 07-MAY-06 113 sql.com 07-MAY-06 SQL> COMMIT; Commit complete. SQL> SELECT * FROM fyi_links; ID URL NOTES COUNTS CREATED ------- ---------------- ---------- ---------- --------- 101 FYICENTER.COM 07-MAY-06 110 CENTERFYI.COM 07-MAY-06
As you can see that two records were deleted from another session after the HR session started the READ ONLY transaction. The deleted records was not impacting any query statements until the transaction was ended with the COMMIT statement.
⇒ Restrictions in a READ ONLY Transaction in Oracle
⇐ What Is a READ ONLY Transaction in Oracle
2019-08-19, 1728🔥, 0💬
Popular Posts:
How to execute statements under given conditions in SQL Server Transact-SQL? How to use IF ... ELSE ...
How To Calculate DATETIME Value Differences Using the DATEDIFF() Function in SQL Server Transact-SQL...
How To Get Year, Month and Day Out of DATETIME Values in SQL Server Transact-SQL? You can use DATEPA...
Where to find answers to frequently asked questions on Storage Engines: MyISAM, InnoDB and BDB in My...
How Fixed Length Strings Are Truncated and Padded in SQL Server Transact-SQL? When the length of the...