等值更新的两种方式

来源:互联网 发布:流体网络理论 编辑:程序博客网 时间:2024/04/29 11:22

方式一:使用游标的方式

declare
  v_jobcode%hr_post_info.jobcode          ;
  v_KEYPOSTSFLAG%hr_post_info.keypostsflag;
  v_KEYPOSTSDESC%hr_post_info.keypostsdesc;
  --v_khnumber mt_kh.khnumber%type;
  CURSOR cur_hr_post_info is
    select KEYPOSTSFLAG, KEYPOSTSDESC, jobcode
      from hr_post_info@db107_link;
begin

  open cur_hr_post_info;
  loop
    fetch cur_length
      into v_jobcode, v_KEYPOSTSDESC, v_KEYPOSTSFLAG;
    EXIT WHEN cur_hr_post_info%NOTFOUND;
    update cur_hr_post_info
       set KEYPOSTSDESC = V_KEYPOSTSDESC, KEYPOSTSFLAG = v_KEYPOSTSFLAG
     where jobcode = v_jobcode;
    commit;
  end;

 

方式二:使用子查询的方式

 

update min a
   set name =
       (select name from min@db107_link b where b.id = a.id)
 where exists (select 1 from min@db107_link b where b.id = a.id);

 

注:此时id必须为主键!

0 0
原创粉丝点击