Join the OracleApps88 Telegram group @OracleApps88to get more information on Oracle EBS R12/Oracle Fusion applications.

If you are facing any issues while copying the Code/Script or any issues with Posts, Please send a mail to OracleApp88@Yahoo.com or message me at @apps88 or +91 905 957 4321 in telegram.

Monday, March 16, 2015

Oracle REF Cursor Example

CREATE OR REPLACE PROCEDURE get_emp_rs (p_deptno      IN     emp.deptno%TYPE,
                                        p_recordset      OUT SYS_REFCURSOR)
AS
BEGIN
   OPEN p_recordset FOR
        SELECT ename, empno, deptno
          FROM emp
         WHERE deptno = p_deptno
      ORDER BY ename;
END get_emp_rs;

-- The resulting cursor can be referenced from PL/SQL as follows.
DECLARE
   l_cursor   SYS_REFCURSOR;
   l_ename    emp.ename%TYPE;
   l_empno    emp.empno%TYPE;
   l_deptno   emp.deptno%TYPE;
BEGIN
   GET_EMP_RS (p_deptno => 30, p_recordset => l_cursor);

   LOOP
      FETCH l_cursor INTO l_ename, l_empno, l_deptno;

      EXIT WHEN l_cursor%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE (l_ename || ' | ' || l_empno || ' | ' || l_deptno);
   END LOOP;

   CLOSE l_cursor;

END;

No comments:

Post a Comment

If you are facing any issues while copying the Code/Script or any issues with Posts, Please send a mail to OracleApp88@Yahoo.com or message me at @apps88 or +91 905 957 4321 in telegram.
Best Blogger TipsGet Flower Effect