未使用PL / SQL中的Cursor进行更新

时间:2017-08-08 12:39:17

标签: sql oracle11g

declare cursor C1 is select vc_emp_id ,vc_rep_to from hrpay.persdet where vc_emp_id in
(select vc_emp_id from hrpay.mst_timesheet 
 where vc_cur_mgr_id = '85' and vc_status = 'P'and vc_emp_id =1214);
 begin for emp_rec in C1 loop
 update 
 hrpay.mst_timesheet set vc_cur_mgr_id =emp_rec.vc_rep_to 
  where vc_cur_mgr_id = '85' and vc_status ='P'and vc_emp_id=emp_rec.vc_emp_id; 
 commit; 
 end loop; end;

已声明CURSOR但它没有更新相同。

1 个答案:

答案 0 :(得分:2)

根据你的谓词,你有vc_emp_id = 1214,你可以试试这个:

update hrpay.mst_timesheet
set vc_cur_mgr_id = (select vc_emp_id
                    from hrpay.persdet
                    where vc_emp_id = 1214 
                      and rownum = 1)
where vc_cur_mgr_id = '85'
  and vc_status = 'P'
  and vc_emp_id = 1214;