GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 13 of 241    Print  
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 closes
when all the records have been processed.
 
     eg. FOR emp_rec IN C1 LOOP
          salary_total := salary_total +emp_rec sal;
          END LOOP;



  
Total Answers and Comments: 4 Last Update: May 06, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
September 20, 2005 07:44:01   #1  
kishorebabukm        

RE: What is a cursor for loop ?

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.


 
Is this answer useful? Yes | No
September 20, 2006 11:54:27   #2  
rashid        

RE: What is a cursor for loop ?
cursor for loop is use for automatically open fetch close
 
Is this answer useful? Yes | No
January 31, 2008 10:49:47   #3  
g_sidhu Member Since: August 2007   Contribution: 122    

RE: What is a cursor for loop ?

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.


 
Is this answer useful? Yes | No
May 06, 2008 05:46:58   #4  
krishnaindia2007 Member Since: September 2007   Contribution: 854    

RE: What is a cursor for loop ?
Cursor for loop implicitly declares a loop index as rowtype. It uses result of query to determine dynamically no of times the loop is to be repeated. It performs open fectch close operations implicitly.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape