Loading...
Corporate Training
current of
interview Questions
Online Training
Oracle
Oracle PL SQL
Overview
SQL PL/SQL
update
virtualnuggets
https://oraclesqlplsqlonlinetraining.blogspot.com/2016/05/plsql-where-currentof-for-update.html
The WHERE CURRENT OF clause is used in some UPDATE and DELETE statements.
The WHERE CURRENT OF clause in an UPDATE or DELETE statement states that the most recent row fetched from the table should be updated or deleted. We must declare the cursor with the FOR UPDATE clause to use this feature.
Inside a cursor loop, WHERE CURRENT OF allows the current row to be directly updated.
When the session opens a cursor with the FOR UPDATE clause, all rows in the return set will hold row-level exclusive locks. Other sessions can only query the rows, but they cannot update, delete, or select with FOR UPDATE.
Oracle provides the FOR UPDATE clause in SQL syntax to allow the developer to lock a set of Oracle rows for the duration of a transaction.
The syntax of using the WHERE CURRENT OF clause in UPDATE and DELETE statements follows:
WHERE [CURRENT OF cursor_name | search_condition]
The following example opens a cursor for employees and updates the commission, if there is no commission assigned based on the salary level.
The FOR UPDATE clause in the SELECT statement can only be specified in the top level; subqueries cannot have this clause.
Another Example of WHERE CURRENT OF
Go through all Maths students and set all GPA’s under 4.0 to 4.0!
DECLARE
thisStudent Student%ROWTYPE;
CURSOR Maths_Student IS
SELECT * FROM Student WHERE SID IN
(SELECT SID FROM Take WHERE CID = ’CS145’)
FOR UPDATE;
BEGIN
OPEN Maths_Student;
LOOP
FETCH Maths_Student INTO thisStudent;
EXIT WHEN (Maths_Student%NOTFOUND);
IF (thisStudent.GPA < 4.0) THEN
UPDATE Student SET GPA = 4.0
WHERE CURRENT OF Maths_Student;
END IF;
END LOOP;
CLOSE Maths_Student;
END;
.
RUN;
Corporate Training,
current of,
interview Questions,
Online Training,
Oracle,
Oracle PL SQL,
Overview,
SQL PL/SQL,
update,
virtualnuggets
virtualnuggets
4208591000860128024
Post a Comment
Home
item
Popular Posts
-
SQL full form for Structured Query Language and it is usually referred to as SEQUEL. SQL is effortless language to learn. SQL is a Nonproc...
-
There are three major categories: 1. Data definition language (DDL) : This is used a set of commands that defines data ...
-
There are 3 Different Division Categories in PL-SQL 1. Data definition language (DDL): This is used a set of commands that de...
-
26) Display the total number of employee working in the company. SQL>select count(*) from emp; 27) Display ...
-
Cursor-Based records Cursor-Based record has fields that match in name, datatype, and order to the final list of columns in the cursor...
-
The WHERE CURRENT OF clause is used in some UPDATE and DELETE statements. The WHERE CURRENT OF clause in an UPDATE or DELETE statem...
-
1) Display the details of all employees SQL>Select * from emp; 2) Display the depart information from department table SQL>select *...
-
SQL stands for Structured Query Language. and it is generally referred to as SEQUEL. SQL is simple language to learn. SQL is a Nonprocedur...
-
Oracle SQL Developer is a free integrated development environment that simplifies the development and management of Oracle Database in bot...
Thanks for sharining such a usefull information
ReplyDeleteoracle Training in mumbai
Thanks for sharing this great information on Oracle APEX. Actually I was looking for the same information on internet for Oracle Apex Interview Questions and Answers and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject, you can learn more about Oracle APEX by attending Oracle APEX Training.
ReplyDeleteThanks for the nice blog here.I was searching this one for a long time.This blog is very helpful for my studies..I got another one site also,which is same as yours Oracle BPM.Check this one also Oracle Fusion HCM Sure it will be helpful for you too..Once more iam thanking you for your creative blog.
ReplyDelete