Tuesday, May 24, 2011

BASIC CURSOR

----- SYMPL CURSOR EXAMPLE

SET SERVEROUTPUT ON
DECLARE
v_emp_id SCOTT.EMP.empno%TYPE;
v_emp_name SCOTT.EMP.ename%TYPE;
v_sal SCOTT.EMP.sal%TYPE;

CURSOR giftCursor IS SELECT empno, ename, sal FROM SCOTT.EMP ORDER BY empno;

BEGIN
OPEN giftCursor;

LOOP
FETCH giftCursor INTO v_emp_id, v_emp_name, v_sal;

EXIT WHEN giftCursor%NOTFOUND;

DBMS_OUTPUT.PUT_LINE('v_empno = ' || v_emp_id || ', v_emp_name = ' || v_emp_name ||', v_sal = ' || v_sal);
END LOOP;
CLOSE giftCursor;

END;
/

No comments:

Post a Comment