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

Slides:



Advertisements
Similar presentations
1 Chapter 10 Protecting Data Integrity in a Multiuser Environment.
Advertisements

Manipulating Data Schedule: Timing Topic 60 minutes Lecture
ORACLE TRANSACTIONS A transaction begins with the first executable SQL statement after a commit, rollback or connection made to the Oracle engine. All.
Transaction Processing. Objectives After completing this lesson, you should be able to do the following: –Define transactions effectively for an application.
9-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language A DML statement is executed when you: – Add new rows to a table.
Allowing Multi-user Access Grant – GRANT ON TO |WITH GRANT OPTION | –GRANT TO | WITH ADMIN OPTION| – can be PUBLIC or a role – can be ALL Revoke – REVOKE.
1 Data Concurrency David Konopnicki 1997 Revised by Mordo Shalom 2004.
Chapter 4B: More Advanced PL/SQL Programming
Module 15: Managing Transactions and Locks. Overview Introduction to Transactions and Locks Managing Transactions SQL Server Locking Managing Locks.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Exception Handling in PL/SQL. POINTS TO DISCUSS What is Exception Handling Structure of Exception Handling Section Types of Exceptions.
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.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
Bordoloi and Bock CURSORS. Bordoloi and Bock CURSOR MANIPULATION To process an SQL statement, ORACLE needs to create an area of memory known as the context.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
Bordoloi and Bock EXCEPTIONS. Bordoloi and Bock Errors Two types of errors can be found in a program: compilation errors and runtime errors. There is.
Cursor and Exception Handling By Nidhi Bhatnagar.
Oracle10g Developer: PL/SQL Programming1 Objectives Manipulating data with cursors Managing errors with exception handlers Addressing exception-handling.
Chapter 4 Cursors and Exception Handling Oracle10g Developer:
Security, Transactions, and Views. Security Achieved through GRANT & REVOKE Assumes the database can recognize its users and verify their identity can.
Allowing Multi-user Access Grant – GRANT ON TO – |WITH GRANT OPTION / WITH ADMIN OPTION| – can be PUBLIC or a role – can be all Revoke – REVOKE ON FROM.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
Security, Transactions, and Views. About Security As is the case in most shared environments, the DBMS also must implement a security mechanism that allows.
DB2. 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/DB01/003 Version No:2.0a Session Plan Introduction to Concurrency Control Different types.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
Trapping Oracle Server Exceptions. 2 home back first prev next last What Will I Learn? Describe and provide an example of an error defined by the Oracle.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
What is a Package? A package is an Oracle object, which holds other objects within it. Objects commonly held within a package are procedures, functions,
Objectives Database triggers and syntax
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Business Solutions. Formatting It is sometimes necessary to alter the output of a query for the sake of readability such as in report generation. This.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
ITEC 224 Database Programming PL/SQL Lab Cursors.
1 Handling Exceptions Part F. 2 Handling Exceptions with PL/SQL What is an exception? Identifier in PL/SQL that is raised during execution What is an.
Giovanni Chierico | May 2012 | Дубна Data Concurrency, Consistency and Integrity.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
implicit and an explicit cursor
Using SQL in PL/SQL Oracle Database PL/SQL 10g Programming Chapter 4.
Session 1 Module 1: Introduction to Data Integrity
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Handling Exceptions. Objectives What is exception Types of exceptions How to handle exceptions Trapping pre defined oracle errors.
Module 11: Managing Transactions and Locks
Relational Database Management System(RDBMS) Structured Query Language(SQL)
PRACTICE OVERVIEW PL/SQL Part Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
©Bob Godfrey, 2002, 2005 Lecture 17: Transaction Integrity and Concurrency BSA206 Database Management Systems.
Module 14: Managing Transactions and Locks. Overview Introducing Transactions and Locks Managing Transactions Understanding SQL Server Locking Architecture.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
1 Copyright © 2004, Oracle. All rights reserved. PL/SQL Programming Concepts: Review.
Pl/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-3
Active Database Concepts
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Handling Exceptions.
Introduction to Oracle9i: SQL
Advanced PL/SQL Programing
On transactions, and Atomic Operations
Handling Exceptions.
On transactions, and Atomic Operations
HAVING,INDEX,COMMIT & ROLLBACK
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
PRACTICE OVERVIEW PL/SQL Part - 1.
Objectives Define and describe transactions
Prof. Arfaoui. COM390 Chapter 9
DB Concurrency ITEC 340 Database I Dr. Ian Barland
Presentation transcript:

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

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.

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:

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 = ` ' 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]

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:

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}

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.