Tuesday, November 04, 2008

Oracle PLSQL Cursor Example

DECLARE

CURSOR c_emp (p_dept VARCHAR2) IS
SELECT ename, salary
FROM emp
WHERE deptno = p_dept
ORDER BY ename;

r_dept DEPT%ROWTYPE;

BEGIN

OPEN c_emp (r_dept.deptno);
LOOP
FETCH c_emp INTO v_ename, v_salary;
EXIT WHEN c_emp%NOTFOUND;

END LOOP;
CLOSE c_emp;

END;

No comments: