SQL> var rset refcursor
SQL> CREATE OR REPLACE PACKAGE Get_sys_RefCursor IS
2 function F_get_emp_by_dept(pFirstDept in emp.deptno%type,
3 pLastDept in emp.deptno%type)
4 return sys_refcursor;
5 end Get_sys_RefCursor;
6 /
已建立套裝程式.
SQL> create or replace package body Get_sys_RefCursor is
2 function F_get_emp_by_dept(pFirstDept in emp.deptno%type,
3 pLastDept in emp.deptno%type)
4 return sys_refcursor is
5 csGetemp sys_refcursor;
6 begin
7 open csGetemp for
8 SELECT *
9 FROM emp
10 WHERE emp.deptno BETWEEN pFirstDept AND pLastDept
11 ORDER BY emp.ename;
12 return csGetemp;
13 end F_get_emp_by_dept;
14 end Get_sys_RefCursor;
15 /
已建立套裝程式主體.
SQL> exec :rset := get_sys_refcursor.f_get_emp_by_dept(10,20);
PL/SQL 程序順利完成.
SQL> print rset;
EMPNO ENAME JOB MGR HIREDATE
---------- -------------------- ------------------ ---------- ----------
SAL COMM DEPTNO
---------- ---------- ----------
7876 ADAMS CLERK 7788 12-1月 -83
1100 20
7782 CLARK MANAGER 7839 09-1月 -81
2450 10
7902 FORD ANALYST 7566 03-12月-81
3000 20
7566 JONES MANAGER 7839 02-4月 -81
2975 20
7839 KING PRESIDENT 17-11月-81
5000 10
7934 MILLER CLERK 7782 23-1月 -82
1300 10
7788 SCOTT ANALYST 7566 09-12月-82
3000 20
7369 SMITH CLERK 7902 17-10月-80
800 20
已選取 8 個資料列.
SQL>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29987/viewspace-51739/,如需转载,请注明出处,否则将追究法律责任。