How To Manage Transaction Isolation Level?
Submitted by: AdministratorTransaction 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:
<pre>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: '
7 || total_salary);
8 -- Other sessions may change salaries of some records
9 SELECT SUM (salary) INTO total_salary FROM employees;
10 DBMS_OUTPUT.PUT_LINE('Total salary 2: '
11 || total_salary);
12 COMMIT;
13 END;
14 /</pre>
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.
Submitted by: Administrator
<pre>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: '
7 || total_salary);
8 -- Other sessions may change salaries of some records
9 SELECT SUM (salary) INTO total_salary FROM employees;
10 DBMS_OUTPUT.PUT_LINE('Total salary 2: '
11 || total_salary);
12 COMMIT;
13 END;
14 /</pre>
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.
Submitted by: Administrator
Read Online Oracle Database Job Interview Questions And Answers
Top Oracle Database Questions
☺ | How Much Memory Your 10g XE Server Is Using? |
☺ | How Run SQL*Plus Commands That Are Stored in a Local File? |
☺ | How To Run SQL*Plus Commands in SQL Developer? |
☺ | What Is the Relation of a User Account and a Schema? |
☺ | How To Check Your Oracle Database 10g XE Installation? |
Top DB Oracle Categories
☺ | Oracle PL-SQL Interview Questions. |
☺ | Oracle DBA Interview Questions. |
☺ | Oracle D2K Interview Questions. |
☺ | OCI Interview Questions. |
☺ | Oracle RMAN Interview Questions. |