Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8363541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:12:05+00:00 2026-06-09T12:12:05+00:00

I am using PL/SQL (Oracle 11g) to update the EMPLOYEES table salary column. I

  • 0

I am using PL/SQL (Oracle 11g) to update the EMPLOYEES table salary column.

I have used two separate scripts to do the same thing i.e update the salary of employees.

One script uses FOR UPDATE OF statement where as another script doesn’t uses it. In both cases I found that oracle holds the row level locks until we execute the ROLLBACK or COMMIT commands.

Then what is the difference in between two scripts?

Which one is better to use?

Here are the two scripts I am talking about:

-- Script 1: Uses FOR UPDATE OF

declare
cursor cur_emp
is
select employee_id,department_id from employees where department_id = 90 for update of salary;
begin
  for rec in cur_emp
  loop
    update Employees
    set salary = salary*10
    where current of cur_emp;
   end loop;
end;


--Script 2: Does the same thing like script 1 but FOR UPDATE OF is not used here

declare
cursor cur_emp
is
select employee_id,department_id from employees where department_id = 90;
begin
  for rec in cur_emp
  loop
    update Employees
    set salary = salary*10
    where Employee_ID = rec.employee_id;
   end loop;
end;

I found that Oracle acquired the row level locks on both cases. So, what is the benefit of using FOR UPDATE OF and Which is the better way of coding?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:12:07+00:00Added an answer on June 9, 2026 at 12:12 pm

    When you specify FOR UPDATE, the row is locked at the point that you SELECT the data. Without the FOR UPDATE, the row is locked at the point you UPDATE the row. In the second script, another session could potentially lock the row between the time that the SELECT was executed and the point that you tried to UPDATE it.

    If you are dealing with a SELECT statement that returns relatively few rows and a tight inner loop, it is unlikely that there will be an appreciable difference between the two. Adding a FOR UPDATE on the SELECT also gives you the opportunity to add a timeout clause if you don’t want your script to block indefinitely if some other session happens to have one of the row you’re trying to update locked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using oracle 11g sql developer I have a varchar2 column with dates as
I'm using Oracle 11g R2. I have a table with 9.1 billion rows. When
On an Oracle 11g engine using PL/SQL I have logic that runs like this
I am using Oracle 11g r2 . I have a table that stores images
I'm using Squirrel SQL with Oracle. I often have to write quick queries for
I am new to Oracle. I have been using SQL-Server for the past 3
I'm using Oracle 11g Standard Edition. I would like to log all SQL queries,
Using Oracle 11g I want a single exception to an otherwise sorted table select
I have an SQL MERGE statement working perfectly in Oracle 11g (development environment), but
I want to extract text from a column using regular expressions in Oracle 11g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.