SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Manage Transaction Isolation Level?

Go down

How To Manage Transaction Isolation Level? Empty How To Manage Transaction Isolation Level?

Post by Micheal Tue Jan 19, 2010 8:13 pm

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.

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum