日期:2014-05-16  浏览次数:20423 次

数据库 sql for loop 常用脚本更新数据
declare
  i    number := 1;
  temp varchar2(50);
  yizi varchar2(60);
begin
  for tttt in (select aa.code, aa.value from aa) loop
    select b.id
      into temp
      from tb_test1 b
     where b.project_code = tttt.value;
    select b.orgexattribute1id into yizi from tb_test1 b where b.id = temp;
    update tb_test2 mbs
       set mbs.ID_SUBJECT = temp, mbs.id_factor = yizi
     where mbs.id_budget_unit = tttt.code;
    i := i + 1;
    commit;
  end loop;
  dbms_output.put_line(i);
end;