Reputation: 253
I have an infinite loop with Cursor :
DECLARE
CURSOR cursor_ab IS
SELECT num_ab FROM abonne;
BEGIN
OPEN cursor_ab;
LOOP
FETCH cursor_ab INTO numeroAb;
dbms_output.put_line(numeroAb);
END LOOP;
CLOSE cursor_ab;
END;
/
Do you have an idea ?
Thank,
Upvotes: 1
Views: 2050
Reputation: 17429
As has already been pointed out, when writing a loop this way, you need to specify the exit condition:
DECLARE
CURSOR cursor_ab IS
SELECT num_ab FROM abonne;
BEGIN
OPEN cursor_ab;
LOOP
FETCH cursor_ab INTO numeroab;
EXIT WHEN cursor_ab%NOTFOUND;
DBMS_OUTPUT.put_line (numeroab);
END LOOP;
CLOSE cursor_ab;
END;
/
However, you can accomplish the same thing in PL/SQL by letting the loop manage the cursor:
DECLARE
CURSOR cursor_ab IS
SELECT num_ab FROM abonne;
BEGIN
FOR numeroab IN cursor_ab LOOP
DBMS_OUTPUT.put_line (numeroab.num_ab);
END LOOP;
END;
/
Upvotes: 4