Oracle存储过程中的for循环

for循环

简单的for循环

declare
  cursor cur is select * from test
  aw_row test%rowtype;
begin
   for tmp in cur
      loop
      insert into test1(id,ishavecommit,createtime)values(tmp.id,tmp.ishavecommit,sysdate);
end loop;
commit;
end;

在循环体中查询、修改、新增操作(使用case判断条件)

declare
	iscommit number(1);
  cursor cur is select * from test where havecommit=1;
  aw_row test%rowtype;
begin
   for tmp in cur
      loop
		select (case when id >0 then 1 else 0 end) into iscommit from test where id=tmp.id;
    	insert into test1(id,havecommit,createtime)values(tmp.id,iscommit ,sysdate);
        update table test1 set havecommit = tmp.havecommit where id = tmp.id;
end loop;
commit;
end;

你可能感兴趣的:(数据库)