一般循环语句有两种:

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语句。

相关文章:

  • 2021-07-13
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-25
  • 2021-12-23
  • 2022-02-12
  • 2021-12-25
  • 2021-12-23
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案