Using for update, PL-SQL Programming


If you declare a cursor which will be referenced in the CURRENT OF clause of an UPDATE or DELETE statement, you should use the FOR UPDATE clause to obtain an exclusive row locks. An illustration is as shown below:


CURSOR c1 IS SELECT empno, sal FROM emp

WHERE job = 'SALESMAN' AND comm > sal


The FOR UPDATE clause identifies the row which will be updated or deleted, then locks each & every row in the result set. This is helpful when you want to base an update on the existing values in a row. In that situation, you should make sure that the row is not changed by the other user before the update.

The elective keyword NOWAIT tells the Oracle not to wait if the table has been locked by the other user. The Control is immediately returned to your program so that it can do the other work before trying again to obtain the lock. If you omit the keyword NOWAIT, the Oracle waits until the table is available.

All rows are locked when you open the cursor, they are not liked fetched. The rows are unlocked when you commit or roll back the transaction. And hence, you cannot fetch from a

When querying the multiple tables, you can use the FOR UPDATE clause to lock up the row locking to the particular tables. The Rows in a table are locked only if the FOR UPDATE OF the clause refers to the column in that table. For illustration, the following query locks rows in the emp table but not in the dept table:


CURSOR c1 IS SELECT ename, dname FROM emp, dept

WHERE emp.deptno = dept.deptno AND job = 'MANAGER'


As the next illustration shows, you use the CURRENT OF clause in an UPDATE or DELETE statement to refer to the newest row fetched from a cursor:


CURSOR c1 IS SELECT empno, job, sal FROM emp FOR UPDATE;



OPEN c1;




UPDATE emp SET sal = new_sal WHERE CURRENT OF c1;


Posted Date: 10/4/2012 5:20:41 AM | Location : United States

Related Discussions:- Using for update, Assignment Help, Ask Question on Using for update, Get Answer, Expert's Help, Using for update Discussions

Write discussion on Using for update
Your posts are moderated
Related Questions
Need to change mysql query to PDO Project Description: I want someone to convert me 1 .php file that includes some sql/mysql stuff to PDO is a very small file. Skills requ

Use Object Types and Collections The Collection types and object types increase your efficiency by allowing for the realistic data modeling. The Complex real-world entities an

Example of Table Literal - SQL Example: A Table Literal (correct version) VALUES ('S1', 'C1', 'Anne'), ('S1', 'C2', 'Anne'), ('S2', 'C1', 'Boris'), ('S3', 'C3'

%ISOPEN The Oracle closes the SQL cursor automatically after executing its related SQL statement. As a result, the %ISOPEN forever yields FALSE.

DECLARE : This keyword signals the beginning of the declarative section of the PL/SQL block, that contains local declarations. The Items declared locally exist only within the

COSMOZOI C THEORY - Richter (1865) proposed the cosmozoic theory that says that life came by spores (cosmozoa) or other particles from other planets on the earth.

Implicit Cursors The Oracle implicitly opens a cursor to process each SQL statement not related with an explicitly declared cursor. The PL/SQL lets you refer to the most recen

Pl/SQL Expressions The Expressions are constructed by using the operands and operators. An operand is a constant, literal, variable, or function call which contributes a value

Parameter Default Values As the illustration below shows, you can initialize the IN parameters to the default values. In that way, you can pass various numbers of actual par

Declaring Objects: You can use the object types wherever built-in types like CHAR or NUMBER can be used. In the block below, you can declare object r of type Rational. Then, yo