Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CONCURRENCY CONTROL IN ORACLE Users manipulate Oracle table data via SQL or PL/SQL sentences. An Oracle transaction can be made up of a single SQL. sentence.

Similar presentations


Presentation on theme: "1 CONCURRENCY CONTROL IN ORACLE Users manipulate Oracle table data via SQL or PL/SQL sentences. An Oracle transaction can be made up of a single SQL. sentence."— Presentation transcript:

1 1 CONCURRENCY CONTROL IN ORACLE Users manipulate Oracle table data via SQL or PL/SQL sentences. An Oracle transaction can be made up of a single SQL. sentence or several SQL sentences. This gives rise to Single Query Transactions and Multiple Query Transactions i.e. SQT and MQT Oracle's Default Locking Strategy - Implicit Locking: Since the Oracle engine has a Fully automatic locking strategy, it has to decide on two issues: Type of Lock to be applied Level of Lock to be applied Types of Locks: The type of lock to be placed on a resource depends on the operation being performed on that resource. Operations on tables can be distinctly grouped into two categories: Read Operations : SELECT statements Write Operations: INSERT, UPDATE, DELETE statements

2 2 The two Types of locks supported by Oracle are: Shared locks: Shared locks are placed on resources whenever a Read operation (SELECT) is performed. Multiple shared locks can be simultaneously set on a resource. Exclusive locks: Exclusive locks are placed on resources whenever Write operations (INSERT, UPDATE and DELETE) are performed. Only one exclusive lock can be placed on a resource at a time i.e. the first user who acquires an exclusive lock will continue to have the sole ownership of the resource, and no other user can acquire an exclusive lock on that resource. Levels of Locks: Oracle provides the following three levels of locking: Row level. Page level Table level The Oracle engine decides on the level to be used by the presence or absence of a where condition in the SQL sentence. if the WHERE clause evaluates to only one row in the table, a row level lock is used. If the WHERE clause evaluates to a set of data, a page level lock is used. If there is no WHERE clause, (i.e. the query accesses the entire table,) a table level lock is used.

3 3 Explicit Locking: The technique of lock taken on a table or its resources by a user is called Explicit Locking. Who can explicitly lock? Users can lock tables they own or any tables on which they have been granted table privileges (such as select, insert, update, delete). The Select........For Update statement: Example: Two client machines Client A and Client B are generating sales orders simultaneously Client A fires the following select statement Client A> SELECT * FROM sales order WHERE order no = `000001 ' FOR UPDATE;

4 4 Client B> SELECT * FROM sales order WHERE order no = '000001 ' FOR UPDATE; If Client B fires the following select statement now with a NOWAIT clause Client B> SELECT * FROM sales_order WHERE order no = ‘000001’ FOR UPDATE NOWAIT; Output: Since Client A has already locked the record 000001 when Client B tries to acquire a shared lock on the same record the Oracle Engine displays the following message: SQL> 00054: resource busy and acquire with nowait specified. NOWAIT: indicates that the Oracle engine should immediately return to the user with a message, if the resources are busy. If omitted, the Oracle engine will wait till resources are available forever.

5 5 Using lock table statement: Focus: Two client machines Client A and Client B are performing data manipulation on the table emp.  Client A has locked the table in exclusive mode  ( i.e. only querying of records is allowed nn the en:p table by Client B). Syntax: Client A> LOCK TABLE emp IN Exclusive Mode NOWAIT; Output: Table (s) Locked. o Client A performs an insert operation but does not commit the transaction. ' Syntax: Client A> INSERT INTO emp VALUES (`E0006', Ajay',10, 5400); Output: 1 row created.

6 6 Client B performs a view operation. Syntax: Client B> SELEC T emp code. emp name FROM emp; Output: Emp codeEmp name EOOOI Lakshimi E0002 Vaishali E0003 Mita E0004 Praveen E0005 Aditya Client B performs an insert operation Syntax: Client B> INSERT INTO emp VALUES ('E0007', 'Suttitct',10, 5400); Output: Client B's SQL DML enters into a wait state waiting for Client A to release the locked resource by using a `Commit' or `Rollback' statement.

7 7 ORACLE'S NAMED EXCEPTION HANDLERS The Oracle engine has a set of pre-defined Oracle error handlers caned Named Exceptions. These error handlers are referenced by their name. The following are some of the pre-defined Oracle named exception handlers: Pre-determined internal PL/SOL exceptions: DUP_VAL_ON INDEX: Raised when an insert or update attempts to create two rows with duplicate values in column/s constrained by a unique index. LOGIN_DENIED; Raised when an invalid username/password was used to log onto Oracle. NO DATA_FOUND: Raised when a select statement returns zero rows. NOT LOGGED_ON: Raised when PL/SQL issues an Oracle call without being logged onto Oracle: PROGRAM ERROR Raised when PL/SQL figs an internat problem. TIMEOUT ON_RESOURCE: Raised when Oracle has been waiting to access a resource beyond the user-defined timeout limit. TOO MANY ROWS: Raised when a select statement returns more than one row. VALUE_ERROR: Raised when the data type or data size is invalid. OTHERS: stands for all other exceptions not explicitly named.

8 8 DECLAIRE ------------------------- BEGINE --------------------- EXCEPTION /* Using the Oracle engine's named exception handler to handle the error condition that may occur if the user enters a salesman_no that is not present In the salesman_master table*/ WHEN no data, found THEN DBMS OUTPUT.PUT LINE(`Salesman No ' // sman no // is not present in the salesman master table'); END


Download ppt "1 CONCURRENCY CONTROL IN ORACLE Users manipulate Oracle table data via SQL or PL/SQL sentences. An Oracle transaction can be made up of a single SQL. sentence."

Similar presentations


Ads by Google