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.

Slides:



Advertisements
Similar presentations
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Explicit Cursors.
Advertisements

PL/SQL.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
Virtual training week 4 structured query language (SQL)
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.
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.
Copyright  Oracle Corporation, All rights reserved. 9 Manipulating Data: INSERT, UPDATE, DELETE.
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
LOCKS Locks are mechanisms used to ensure data integrity while allowing maximum concurrent access to data. Oracle's locking is fully automatic and requires.
Exception Handling in PL/SQL. POINTS TO DISCUSS What is Exception Handling Structure of Exception Handling Section Types of Exceptions.
9 Copyright © 2009, Oracle. All rights reserved. Managing Data Concurrency.
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:
Chapter 6 Additional Database Objects
Security, Transactions, and Views. Security Achieved through GRANT & REVOKE Assumes the database can recognize its users and verify their identity can.
Chapter 5 Data Manipulation and Transaction Control
Introduction to SEQUEL. What is SEQUEL? Acronym for Structural English Query Language Acronym for Structural English Query Language Standard language.
Copyright © 2011 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. SQL Workshop Day 3.
Oracle Locking Michael Messina Principal Database Analyst Indiana University.
Program with PL/SQL. Interacting with the Oracle Server.
Security, Transactions, and Views. About Security As is the case in most shared environments, the DBMS also must implement a security mechanism that allows.
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.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
PL/SQL Block Structure DECLARE - Optional Variables, cursors, user-defined exceptions BEGIN - Mandatory SQL Statements PL/SQL Statements EXCEPTIONS - Optional.
Manipulating Data in PL/SQL. 2 home back first prev next last What Will I Learn? Construct and execute PL/SQL statements that manipulate data with DML.
Trigger Oracle PL/SQL. Triggers Associated with a particular table Associated with a particular table Automatically executed when a particular event occurs.
Fall 2001Database Systems1 Triggers Assertions –Assertions describe rules that should hold for a given database. –An assertion is checked anytime a table.
Oracle 8i Exception Handling. General Syntax DECLARE --- BEGIN --- EXCEPTION WHEN exception_name1 THEN -Error handling statements WHEN exception_name2.
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,
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.
Using SQL in PL/SQL ITEC 224 Database Programming.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
9 Manipulating Data. 9-2 Objectives At the end of this lesson, you should be able to: Describe each DML statement Insert rows into a table Update rows.
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.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
implicit and an explicit cursor
Handling Exceptions. Objectives What is exception Types of exceptions How to handle exceptions Trapping pre defined oracle errors.
© 2007 by Prentice Hall2-1 Introduction to Oracle 10g Chapter 2 Overview of SQL and SQL*Plus James Perry and Gerald Post.
Module 11: Managing Transactions and Locks
Relational Database Management System(RDBMS) Structured Query Language(SQL)
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.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Overview.
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
 CONACT UC:  Magnific training   
7.5 Using Stored-Procedure and Triggers NAME MATRIC NUM GROUP Muhammad Azwan Bin Khairul Anwar CS2305A Muhammad Faiz Bin Badrol Shah CS2305B.
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
PL/SQL.
Oracle11g: PL/SQL Programming Chapter 4 Cursors and Exception Handling.
Handling Exceptions.
Introduction to Oracle9i: SQL
Manipulating Data Schedule: Timing Topic 40 minutes Lecture
Interacting with the Oracle Server
PL/SQL Scripting in Oracle:
Advanced PL/SQL Programing
Handling Exceptions.
Data Control Language Grant, Revoke.
HAVING,INDEX,COMMIT & ROLLBACK
Chapter 8 Advanced SQL.
Presentation transcript:

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 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 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 = ` ' FOR UPDATE;

4 Client B> SELECT * FROM sales order WHERE order no = ' ' 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 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 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 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 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 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