■ 커서를 사용하는 기본적인 방법을 보여준다.
▶ 예제 코드 (SQL)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
SET SERVEROUTPUT ON; DECLARE CURSOR EMPLOYEE_CURSOR IS SELECT * FROM SCOTT.EMP; V_EMPLOYEE_RECORD EMPLOYEE_CURSOR%ROWTYPE; BEGIN OPEN EMPLOYEE_CURSOR; LOOP FETCH EMPLOYEE_CURSOR INTO V_EMPLOYEE_RECORD; EXIT WHEN EMPLOYEE_CURSOR%NOTFOUND; DBMS_OUTPUT.PUT_LINE(V_EMPLOYEE_RECORD.ENAME); END LOOP; CLOSE EMPLOYEE_CURSOR; END; |