How To Manage Transaction Isolation Level?
SQL tutorial | Interview questions | Oracle :: Interview questions :: Introduction to PL/SQL | Interview questions
Page 1 of 1
How To Manage Transaction Isolation Level?
Transaction isolation level can be managed in a procedure by using the SET TRANSACTION and COMMIT statements. Here is a sample script on how to manage transaction isolation level:
SQL> CREATE OR REPLACE PROCEDURE HR.TOTAL_SALARY AS
2 total_salary NUMBER(12,2);
3 BEGIN
4 SET TRANSACTION READ ONLY;
5 SELECT SUM (salary) INTO total_salary FROM employees;
6 DBMS_OUTPUT.PUT_LINE('Total salary 1: ' || total_salary);
7 -- Other sessions may change salaries of some records
8 SELECT SUM (salary) INTO total_salary FROM employees;
9 DBMS_OUTPUT.PUT_LINE('Total salary 2: ' || total_salary);
10 COMMIT;
11 END;
12 /
SQL> EXECUTE TOTAL_SALARY;
Total salary 1: 691400
Total salary 2: 691400
"READ ONLY" transaction level takes a read only snapshot of the database. This allows other sessions to update the database without any locks. All queries in the session will produces identical results. So both SELECT statements in this script will return the same value guaranteed.
SQL> CREATE OR REPLACE PROCEDURE HR.TOTAL_SALARY AS
2 total_salary NUMBER(12,2);
3 BEGIN
4 SET TRANSACTION READ ONLY;
5 SELECT SUM (salary) INTO total_salary FROM employees;
6 DBMS_OUTPUT.PUT_LINE('Total salary 1: ' || total_salary);
7 -- Other sessions may change salaries of some records
8 SELECT SUM (salary) INTO total_salary FROM employees;
9 DBMS_OUTPUT.PUT_LINE('Total salary 2: ' || total_salary);
10 COMMIT;
11 END;
12 /
SQL> EXECUTE TOTAL_SALARY;
Total salary 1: 691400
Total salary 2: 691400
"READ ONLY" transaction level takes a read only snapshot of the database. This allows other sessions to update the database without any locks. All queries in the session will produces identical results. So both SELECT statements in this script will return the same value guaranteed.
Similar topics
» What Are Transaction Isolation Levels Supported by Oracle?
» Explain different isolation levels
» What is a transaction ?
» What Is a Transaction?
» How To Start a New Transaction?
» Explain different isolation levels
» What is a transaction ?
» What Is a Transaction?
» How To Start a New Transaction?
SQL tutorial | Interview questions | Oracle :: Interview questions :: Introduction to PL/SQL | Interview questions
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Sun Jan 31, 2010 12:35 am by Micheal
» Accessing tables of other users in SQL
Sun Jan 31, 2010 12:34 am by Micheal
» Grouping commands in SQL
Sun Jan 31, 2010 12:32 am by Micheal
» Operations on Result Sets in SQL
Sun Jan 31, 2010 12:31 am by Micheal
» Subqueries in SQL
Sun Jan 31, 2010 12:30 am by Micheal
» Joining Relations in SQL
Sun Jan 31, 2010 12:28 am by Micheal
» Delete comand in SQL
Sun Jan 31, 2010 12:27 am by Micheal
» Update command in SQL
Sun Jan 31, 2010 12:26 am by Micheal
» Insert command in SQL
Sun Jan 31, 2010 12:23 am by Micheal