Tuesday, December 30, 2014

REF CURSOR Procedure as a OUTPUT variable in Oracle as a result set output for JAVA and VB.NET or C#


CREATE OR REPLACE PACKAGE APPS.PRICE_BOOK_PKG
AS
   TYPE R_CURSOR IS REF CURSOR;

   PROCEDURE GETPRICEBOOKDATA (P_PRICEBOOK_REQUEST_ID   IN     NUMBER,
                               cur_pricebookdata           OUT R_CURSOR);

   PROCEDURE GETPRICEBOOKDATA (cur_pricebookdata OUT SYS_REFCURSOR);
END PRICE_BOOK_PKG;


CREATE OR REPLACE PACKAGE BODY APPS.PRICE_BOOK_PKG
AS
   PROCEDURE GETPRICEBOOKDATA (P_PRICEBOOK_REQUEST_ID   IN     NUMBER,
                               cur_pricebookdata           OUT R_CURSOR)
   IS
   BEGIN
      OPEN cur_pricebookdata FOR SELECT   'a', 'b' FROM DUAL;
   END GETPRICEBOOKDATA;

   PROCEDURE GETPRICEBOOKDATA (cur_pricebookdata OUT SYS_REFCURSOR)
   IS
   BEGIN
      OPEN cur_pricebookdata FOR SELECT   'a', 'b' FROM DUAL;
   END;
END PRICE_BOOK_PKG;



/* Formatted on 12/30/2014 10:38:45 AM (QP5 v5.126.903.23003) */
DECLARE
   TYPE R_CURSOR IS REF CURSOR;

   V_CURSOR   R_CURSOR;
   v_a        VARCHAR2 (10);
   v_b        VARCHAR2 (10);
   l_cursor   SYS_REFCURSOR;
BEGIN
   apps.PRICE_BOOK_PKG.GETPRICEBOOKDATA (l_cursor);


   LOOP
      FETCH l_CURSOR
      INTO   v_a, v_b;

      EXIT WHEN l_CURSOR%NOTFOUND;
      DBMS_OUTPUT.put_line (v_a || ' ' || v_b);
   END LOOP;

   CLOSE l_CURSOR;

   apps.PRICE_BOOK_PKG.GETPRICEBOOKDATA (121212, v_CURSOR);

   LOOP
      FETCH v_CURSOR
      INTO   v_a, v_b;

      EXIT WHEN V_CURSOR%NOTFOUND;
      DBMS_OUTPUT.put_line ('Hi ' || v_a || ' ' || v_b);
   END LOOP;

   CLOSE v_CURSOR;
END;

No comments:

Post a Comment