What is a cursor for loop ?

 Cursor  for loop implicitly declares %ROWTYPE as loop index,opens a cursor, fetches rows of values from active set into fields in the record and closeswhen all the records have been processed.      eg. FOR emp_rec IN C1 LOOP          salary_total := salary_total +emp_rec sal;          END LOOP;

Showing Answers 1 - 17 of 17 Answers

kishorebabukm

  • Sep 20th, 2005
 

The for loop in cursors are used to make less statements to write cursor.

if u are opening a cursor normally using the open cursor ,then

open cursor_name;

fetch cursor_name into variable loop

 exit when cursor_name%notfound ;

end loop;

close cursor

in the above statement u have to explicitly open and close the cursor, and also write exit statement to end the cursor loop

if we write the same using for loop then compare the statements.

for varible in cursor_name loop

 statements

end loop;

the above for loop does not need a open and close explicitly since those are involved in the for loop itself.

and also never require the loop to explicitly end using any condition, since it ends the loop if there are no more rows in the memory.

rashid

  • Sep 20th, 2006
 

cursor for loop is use for automatically open ,fetch,close

  Was this answer useful?  Yes

g_sidhu

  • Jan 31st, 2008
 

A cursor FOR loop processes rows in an explicit cursor. It is a shortcut because the cursor is opened, rows are fetched once for each iteration in the loop, the loop exits when the last row is processed, and the cursor is closed automatically. The loop itself is terminated automatically at the end of the iteration where the last row is fetched.
The record is implicitly declared.

  Was this answer useful?  Yes

>By using cursor for loops we can improve performance of the application.
>it avoids explict cursor life cycle(open,fetch,close).
>in cursor for loop the index variable behaves like a record type variable..which is auto initialized.
>we can also use select stmt in place of cursorname
ex:
for i in (select * from emp)                --inline _cursor style
loop                                                   -- i record type variable..emp%rowtype
 ......
end loop;
but here we cant controle the loop explicitely.

PRADEEP

  • Oct 17th, 2012
 

If we use explicit cursor we need to open the cursor and fetching the data and close the cursor.

If we use cursor for loop cursor will open the cursor and fetching data and close the cursor automatically.

  Was this answer useful?  Yes

vasu

  • Oct 20th, 2012
 

Cursor for loop is the one by using this we need not to perform open, close, fetch operations of a cursor..

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions