Difference between FETCH/FOR to loop a CURSOR in PL/SQL

后端 未结 4 1756
有刺的猬
有刺的猬 2020-12-25 08:35

I know that fetching a cursor will give me access to variables like %ROWCOUNT, %ROWTYPE, %FOUND, %NOTFOUND, %ISOPEN

...but I was wondering if there are any other rea

4条回答
  •  不思量自难忘°
    2020-12-25 09:29

    Correct me if I'm wrong but I think both have one nice feature what other one doesn't have.

    With for loop you can do like this:

    for i in (select * from dual)
      dbms_output.put_line('ffffuuu');
    end loop;
    

    And with open .. fetch you can do like this:

    declare
      cur sys_refcursor;
      tmp dual.dummy%type;
    begin
      open cur for 'select dummy from dual';
      loop
        fetch cur into tmp;
        exit when cur%notfound;
        dbms_output.put_line('ffffuuu');
      end loop;
      close cur;
    end;
    

    So with open fetch you can use dynamic cursors but with for loop you can define normal cursor without declaration.

提交回复
热议问题