Oracle--存储过程中之循环语句

一般循环语句有两种:

1)使用for循环实现

declare
  cursor cur is
   select * from tablename;
   aw_row  tablename%rowtype;
begin
   for raw_row in cur
      loop
      dbms_output.put_line('test');
end loop;
end;

注意:for语句直接帮我们做了游标的打开关闭,以及判断工作;所以比较常用。

2)使用while实现:

declare
    cursor cur is
    select * from iss2_foc_response;
    raw_row iss2_foc_response%rowtype;
begin
    open cur;
    FETCH cur
    into raw_row;
    while cur%found
        loop
          dbms_output.put_line('test while');
          FETCH cur
          into raw_row;
      end loop;
   close cur;
end;

注意:这种写法需要打开关闭游标,根据游标的特点,这两种循环的写法是等效的。游标默认打开是只读游标,如果要在用到游标的时候修改游标中的值,需要在游标定义的时候,加上For update语句。

原文地址:https://www.cnblogs.com/xuyufengme/p/8033879.html