Cursor FOR LOOP


/ Published in: SQL
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.