Presentation is loading. Please wait.

Presentation is loading. Please wait.

LOCKS Locks are mechanisms used to ensure data integrity while allowing maximum concurrent access to data. Oracle's locking is fully automatic and requires.

Similar presentations


Presentation on theme: "LOCKS Locks are mechanisms used to ensure data integrity while allowing maximum concurrent access to data. Oracle's locking is fully automatic and requires."— Presentation transcript:

1 LOCKS Locks are mechanisms used to ensure data integrity while allowing maximum concurrent access to data. Oracle's locking is fully automatic and requires no user intervention. The Oracle engine automatically locks table data while executing SQL statements. This type of locking is called Implicit Locking. 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 The rules of locking can be summarized as: DATA being CHANGED cannot be READ Writers wait for other writers, if they attempt to update the same rows at the same time. 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 tan acquire an exclusive lock on that resource.

3 Levels of Locks: A table can be decomposed into rows and a row can be further decomposed into fields. Hence, if an automatic locking system is designed so as to be able to lock the fields of a record, it will be the most flexible locking system available. It would mean that more than one user can be working on a single record in a table i.e. each on a different field of the same record in the same table. Oracle does not provide a field level lock. Oracle provides the following three levels of locking: Row level. Page level Table level 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). Oracle provides facilities by which the default locking strategy can be overridden. Tables) or rows) can be explicitly locked by using either the select:..for update statement; or lock table statement. The Select...For Update statement:

4 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; Using lock table statement: To manually override Oracle's default Pocking strategy by creating a data lack in a specific mode. Syntax: LOCK TABLE tablename [, tablename]... IN (ROW SHARE|ROW EXCLUSIVE|SHARE UPDATE SHARE|SHARE ROW EXCL USIVE|EXCL USIVE } [NOWAIT]

5 Releasing Locks Locks are released under the following circumstances: The transaction is committed successfully using the `Commit' verb. A rollback is performed. A rollback to a save point will release locks set after the specified save point. ERROR HANDLING IN PL/SQL Every PL/SQL block of code encountered by the Gracie engine is accepted as a client. Hence the Oracle engine will make an attempt to execute every SQL sentence within the PL/SQL block. However whsle executing the SQL sentences anything can go wrong and the SQL sentence can fail:

6 If the first word after the action word When, is the exception handler's name then the exception handler executes the code contained in the Then section of the construct as follows: Exception When {Exception Name}Then {User defined action to be carried out}

7 ORACLE'S NAMED EXCEPTION HANDLERS The Oracle engine has a set of pre-defined Oracle error handlers called 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 has an internal problem. TIMEOUT_ON RESOURCE : Raised when Oracle has been waiting to access a resource beyond the user-defined timeout limit.  TOO_NIANY_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

9


Download ppt "LOCKS Locks are mechanisms used to ensure data integrity while allowing maximum concurrent access to data. Oracle's locking is fully automatic and requires."

Similar presentations


Ads by Google