title: use of FOR UPDATE statement
body: <p>I am using PL/SQL (Oracle 11g) to update the <code>EMPLOYEES</code> table salary column. </p>
  
  <p>I have used two separate scripts to do the same thing i.e update the salary of employees. </p>
  
  <p>One script uses <code>FOR UPDATE OF</code> 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 <code>ROLLBACK</code> or <code>COMMIT</code> commands. </p>
  
  <p>Then what is the difference in between two scripts? </p>
  
  <p>Which one is better to use? </p>
  
  <p>Here are the two scripts I am talking about:</p>
  
  <pre><code>-- 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;
  </code></pre>
  
  <p>I found that Oracle acquired the row level locks on both cases. So, what is the benefit of using <code>FOR UPDATE OF</code> and Which is the better way of coding?</p>