PL/SQL Cursors For Loop

Published on by LakshmiSaahul,Dhana Royal

PL/SQL Cursors For Loop
-----------------------------------
PL/SQL cursor FOR loop has one great advantage of loop continued until row not found. In sometime you require to use explicit cursor with FOR loop instead of use OPEN, FETCH, and CLOSE statement.
FOR loop iterate repeatedly and fetches rows of values from database until row not found.


SQL>set serveroutput on
SQL>edit cursor_for_loop
DECLARE
cursor c is select * from emp_information
where emp_no <=2;
tmp emp_information%rowtype;
BEGIN
OPEN c;
FOR tmp IN c LOOP
FETCH c into tmp;
dbms_output.put_line('EMP_No: '||tmp.emp_no);
dbms_output.put_line('EMP_Name: '||tmp.emp_name);
dbms_output.put_line('EMP_Dept: '||tmp.emp_dept);
dbms_output.put_line('EMP_Salary:'||tmp.emp_salary);
END Loop;
CLOSE c;
END;
/

Advertising
To be informed of the latest articles, subscribe:
Comment on this post