• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql

syntax and example of CURSOR FOR Loop in oracle plsql

CURSOR FOR Loop in Oracle PLSQL

November 23, 2012 by techhoneyadmin

A CURSOR FOR Loop in Oracle PLSQL is used whenever we want to retrieve and process every record within a cursor.

The CURSOR FOR loop automatically gets terminated as soon as all the records in the cursor are fetched.

The Syntax for the CURSOR FOR LOOP in Oracle PLSQL is:

FOR cursor_records IN cursor_name
LOOP
{
Statements to be executed;
}
END LOOP;

Example of a CURSOR FOR Loop in Oracle PLSQL is:

CREATE OR REPLACE function TotalSalary
   ( emp_id_in IN NUMBER)
   RETURN VARCHAR2
IS
   total_sal NUMBER(6);

   CURSOR cur_salary IS
     SELECT salary
     FROM employee
     WHERE employee_id = emp_id_in;
BEGIN
   total_sal := 0;
   FOR employee_record IN cur_salary
   LOOP
      total_sal := total_sal + employee_record.salary;
   END LOOP;
   RETURN total_sal;
END;

In the above example the CURSOR FOR loop will terminate automatically when all the records have been fetched from the CURSOR ‘cur_salary’.


Filed Under: loop Tagged With: CURSOR FOR Loop in oracle plsql, CURSOR FOR Loop in oracle sql, CURSORFORLOOPPLSQL, how to use CURSOR FOR Loop in oracle database query, how to use CURSOR FOR Loop in oracle plsql, how to use CURSOR FOR Loop in oracle sql, syntax and example of CURSOR FOR Loop in oracle database query, syntax and example of CURSOR FOR Loop in oracle plsql, syntax and example of CURSOR FOR Loop in oracle sql, using CURSOR FOR Loop in oracle database query, using CURSOR FOR Loop in oracle plsql, using CURSOR FOR Loop in oracle sql

Copyright © 2025 · Parallax Pro on Genesis Framework · WordPress · Log in