how to execute package

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amoldiego
    New Member
    • Jun 2007
    • 28

    how to execute package

    Dear all,

    1)
    I have created package ref test for declaring ref cursor as shown .....
    create or replace package ref_test as
    type empty is ref cursor;
    end;


    2)
    created package ref_use and used the reference of that ref cursor .....

    create or replace package ref_use as
    procedure ref_pro (p_empno number,P_result out ref_test.empty) ;
    end;


    3)
    created package body as shown


    create or replace package body ref_use as
    procedure ref_pro (p_empno number,P_result out ref_test.empty) as
    begin
    open P_result for select ename,sal,deptn o from emp where empno=p_empno;
    end;
    end;
    /


    now i want to execute this package in SQL(+) .could u plz send me the execution code of
    this package
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    to execute any member of the package, it must be qualified by the package name

    if package is PACK1

    PROCEDURE NAME IS PROC1(PI,P2,... .)

    to execute

    SQL> PACK1.PROC1(PI, P2,....)

    Comment

    • amoldiego
      New Member
      • Jun 2007
      • 28

      #3
      Thanks for the answer ... But cud u plz tell me how to execute the given package ....I created Ref cusor type inside the package...
      How to open that ref cursor inside the calling procedure ......
      plz help

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        Once a ref cursor is declared with a package specification means it has global scope .

        ans since your procedure inside the package has an OUT parameter it can't be executed from SQL pronpt.

        For that u need to write an anonymous block.

        Comment

        • amoldiego
          New Member
          • Jun 2007
          • 28

          #5
          That anonymous block i want ..cud u plz send it for given package .

          Comment

          • vergilfrans
            New Member
            • Feb 2009
            • 1

            #6
            You can view the result in the cursor as follows in sql prompt.

            VARIABLE io_cursor refcursor;
            Execute package_name.pr ocedure_name(:i o_cursor);
            print io_cursor;

            (hope this will be useful for others because you must be an expert by now.)

            Comment

            • amitpatel66
              Recognized Expert Top Contributor
              • Mar 2007
              • 2358

              #7
              Try this:

              [code=oracle]

              DECLARE
              ref_cur SYS_REFCURSOR;
              e_name VARCHAR2(100);
              salary NUMBER;
              dept_no NUMBER:
              BEGIN
              ref_use.ref_pro (20,ref_cur);
              LOOP
              EXIT WHEN ref_cur%NOTFOUN D;
              FETCH ref_cur INTO e_name,salary,d ept_no;
              DBMS_OUTPUT.PUT _LINE(e_name||' ,'||salary||',' ||dept_no);
              END LOOP;
              END;
              [/code]

              Comment

              Working...