--in sql*plus, assuming you have scott/tiger schema
SET SERVEROUTPUT ON
CREATE OR REPLACE PROCEDURE TESTSP AS
TYPE DEPTARR IS TABLE OF DEPT%ROWTYPE INDEX BY BINARY_INTEGER;
D_ARR DEPTARR;
TYPE D_CUR IS REF CURSOR RETURN DEPT%ROWTYPE;
C1 D_CUR;
I NUMBER := 1;
BEGIN
-- POPULATE THE PL/SQL TABLE FROM THE CURSOR
OPEN C1 FOR SELECT * FROM DEPT;
LOOP
EXIT WHEN C1%NOTFOUND;
FETCH C1 INTO D_ARR(I);
I := I+1;
END LOOP;
CLOSE C1;
-- DISPLAY THE ENTIRE PL/SQL TABLE
FOR I IN 1..D_ARR.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('DEPTNO : '||D_ARR(I).DEPTNO);
DBMS_OUTPUT.PUT_LINE('DNAME : '||D_ARR(I).DNAME);
DBMS_OUTPUT.PUT_LINE('LOC : '||D_ARR(I).LOC);
DBMS_OUTPUT.PUT_LINE('');
END LOOP;
END;
/
EXECUTE TESTSP;
No comments:
Post a Comment