Posted By

mprabhuram on 09/08/10


Tagged

Oracle PLSQL


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tyster


Cursor FOR LOOP


 / Published in: SQL
 

URL: http://www.techonthenet.com/oracle/loops/cursor_for.php

You would use a CURSOR FOR Loop when you want to fetch and process every record in a cursor. The CURSOR FOR Loop will terminate when all of the records in the cursor have been fetched.

  1. CREATE OR REPLACE FUNCTION TotalIncome
  2. ( name_in IN varchar2 )
  3. RETURN varchar2
  4. IS
  5. total_val number(6);
  6.  
  7. cursor c1 IS
  8. SELECT monthly_income
  9. FROM employees
  10. WHERE name = name_in;
  11.  
  12. BEGIN
  13.  
  14. total_val := 0;
  15.  
  16. FOR employee_rec IN c1
  17. LOOP
  18. total_val := total_val + employee_rec.monthly_income;
  19. END LOOP;
  20.  
  21. RETURN total_val;
  22.  
  23. END;

Report this snippet  

You need to login to post a comment.