Reputation: 11
I am trying to update the employee_id column of table employee_1 for top 151 rows from employee_id column of employees table.But all the rows of employee_id column of employee_1 table is getting up upated with only one row value of employee_id column of table employees.
The code used is:
declare
cursor c1 is select employee_id from employees;
emp_id employees.employee_id%type;
Begin
open c1;
loop
fetch c1 into emp_id;
exit when(c1%rowcount>151);
update employee_1 set employee_id=emp_id;
end loop;
close c1;
end;
How to update the column with different values?
Upvotes: 0
Views: 42
Reputation: 35900
Yes, Because you have not used the WHERE
condition:
update employee_1 set employee_id=emp_id; -- WHERE condition will be needed here
You need to use WHERE
condition such that it identifies only single record from the EMPLOYEE_1
table for each loop.
Upvotes: 1