FOR i in c1 LOOP
UPDATE....
COMMIT;
END LOOP;
CLOSE c1;
Above block hit error: Invalid c1 when CLOSE c1
, updates are running well.Is it possible the cursor closed after loop is ended?
FOR i in c1 LOOP
UPDATE....
COMMIT;
END LOOP;
CLOSE c1;
Above block hit error: Invalid c1 when CLOSE c1
, updates are running well.Is it possible the cursor closed after loop is ended?
When you use syntax FOR xxx in c1 LOOP
then the cursor is closed automatically at the end. You cannot close it twice.
Just skip CLOSE c1;
You have two options:
SQL> declare
2 cursor c1 is select * from dept;
3 c1r c1%rowtype;
4 begin
5 open c1;
6 loop
7 fetch c1 into c1r;
8 exit when c1%notfound;
9 dbms_output.put_line(c1r.dname);
10 end loop;
11 close c1;
12 end;
13 /
ACCOUNTING
RESEARCH
SALES
OPERATIONS
PL/SQL procedure successfully completed.
SQL> begin
2 for cur_r in (select * from dept) loop
3 dbms_output.put_line(cur_r.dname);
4 end loop;
5 end;
6 /
ACCOUNTING
RESEARCH
SALES
OPERATIONS
PL/SQL procedure successfully completed.
SQL>
As you can see, both produce the same result, but the 2nd one is much easier to maintain.
In Option 1 you have to:
In Option 2, you have to:
Pick one you find more appropriate (I'd pick #2, most of the time).
As of the error you got: there's nothing to be closed; as I've said, Oracle does it for you. Remove the CLOSE
command.