oracle 使用游标循环遍历一张表

当有需求需要循环遍历一张表的时候,可以使用游标做此操作,并进行一定的逻辑处理。

 declare 

  begin

  for rec in (select * from  S_LOY_WALLET) loop    -- for 循环S_LOY_WALLET这张表,并赋给rec对象

    if rec.x_oldpamaacct  = '0715'                              --一条一条的进行遍历,进行判断,如果当x_oldpamaacct的值为0715时

then

     update S_LOY_WALLET set  x_oldpamaacct = '0714' where  id = rec.id;   --更新这条记录

     commit;                                                                                                         --提交操作

     end if;

     end loop;

    end;

   

猜你喜欢

转载自blog.csdn.net/qrnhhhh/article/details/81184600