Help needed in Ref cursor

Hi,
I am new to Ref Cursor concepts and I am trying a small block but its throwing error. Pls help me.
PACKAGE SPEC:
CREATE OR REPLACE PACKAGE PKG_JOBINFO AS
PROCEDURE JOBINFO ( v_job_id IN number, p_cursor OUT PKG_JOBINFO.RESULT_REF_CURSOR);
TYPE RESULT_REF_CURSOR IS REF CURSOR;
END PKG_JOBINFO;
PACKAGE BODY:
CREATE OR REPLACE package body PKG_JOBINFO
AS
PROCEDURE JOBINFO ( v_job_id IN number,
p_cursor OUT PKG_JOBINFO.RESULT_REF_CURSOR)
AS
BEGIN
OPEN p_cursor FOR
SELECT JOB_ID,
JOB_NAME,
TABLE_NAME
FROM JOB_INFO
WHERE JOB_ID=V_JOB_ID;
EXCEPTION
WHEN OTHERS THEN
raise;
END;
END;
While compiling the package i am not getting any errors. I am getting errors only while executing
SQL> exec PKG_JOBINFO.JOBINFO ('23');
BEGIN PKG_JOBINFO.JOBINFO ('23'); END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'JOBINFO'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Please help me to resolve this error.
Thanks.

user497267 wrote:
Thanks its working. So if we are using ref cursor we have to execute like this only.To add...
The actual issue you were experiencing was not because you were using ref cursors specifically, but because you had an OUT parameter in your procedure.
When you have an OUT parameter, you need to ensure that you pass in a variable to that parameter of the procedure in order that the procedure can populate it. In your case you were only passing in the first parameter, but you weren't passing in a variable to capture the OUTput.
What Alex showed was that by declaring a variable of the same datatype (ref cursor in your case) and passing that in as the second parameter, that variable was populated with the ref cursor information from inside the procedure. Once that variable was populated, after the procedure call, the data from that ref cursor can be obtained (using SQL*Plus' print command in Alex's example).

Similar Messages

  • Need Urgent Help Reports 6i :  Ref Cursor

    Hi,
    I am creating required SQL for report in my Java program. I want to pass this SQL stmt to my Oracle Report.
    For that , I am storing the SQL stmt in Oracle table and then I want to use that stmt with few additions to fetch data . Is there any good method other than Ref Cursor to do this? Somehow Ref cursor is not working in Reports 6i. Or may be I don't know how to use it.
    Any help will be appreciated !!
    VMJ

    Lexical parameters seem to be much more appropriate tool for this task. You can create entire query as single lexical parameter, and script it in the After Parameter Form trigger any way you need. Just make sure to supply some dummy query as initial value for the lexical parameter, so that the report could create proper data structure.

  • Ref.Cursor Problem - URGENT

    Hi Friends,
    For my report ( calc.rdf ) ,
    I am passing two input parameters P_Client_ID, P_Plan_ID.
    In .rdf, I had a ref.cursor for selecting records based on
    two input parameters values.
    case1:
    P_client_ID = 'SRINI'
    P_Plan_ID = '3232'
    My report is generating the output for plan 3232.
    case2:
    P_client_ID = 'SRINI'
    P_Plan_ID = NULL
    My report is generating the output for all plans.
    case3:
    P_client_ID = 'SRINI'
    P_Plan_ID = '3232,3257,3259'
    My report is not generating any output here.
    Only blanck page i am getting.
    How can i pass multiple plans to ref.cursor at a time ?
    Note:
    I now, we cannot make Lexical references in a PL/SQL statement.
    Any other way to solve this problem ?
    Thanks for Help,
    srini

    I think that you work with 'static' ref cursor.
    From Oracle 8.1.5, we can use 'dynamic' ref cursors.
    With 'dynamic' ref cursor we can avoid the use of lexical parameters in Reports 3.0 / 6i.
    With 'static' ref cursor this is not possible in all cases.
    For example, if we need dynamic WHERE, we practically can't use 'static' ref cursor.
    Example for 'dynamic' ref cursor (dynamic WHERE)
    1. Stored package
    CREATE OR REPLACE PACKAGE report_dynamic IS
    TYPE type_ref_cur_sta IS REF CURSOR RETURN dept%ROWTYPE; -- for Report Layout only
    TYPE type_ref_cur_dyn IS REF CURSOR;
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn;
    END;
    CREATE OR REPLACE PACKAGE BODY report_dynamic IS
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn IS
    l_ref_cur_dyn type_ref_cur_dyn;
    BEGIN
    OPEN l_ref_cur_dyn FOR
    'SELECT * FROM dept WHERE ' || NVL (p_where, '1 = 1');
    RETURN l_ref_cur_dyn;
    END;
    END;
    2.2 Query PL/SQL in Reports
    function QR_1RefCurQuery return report_dynamic.type_ref_cur_sta is
    begin
    return report_dynamic.func_dyn (:p_where);
    end;
    Note that Oracle Reports 3.0 / 6i needs 'static' ref cursor type for building Report Layout.
    So, in package specification we must have both ref cursor types, static for Report Layout
    and dynamic for ref cursor query.
    Regards
    Zlatko Sirotic

  • Dynamic sql and ref cursors URGENT!!

    Hi,
    I'm using a long to build a dynamic sql statement. This is limited by about 32k. This is too short for my statement.
    The query results in a ref cursor.
    Does anyone have an idea to create larger statement or to couple ref cursors, so I can execute the statement a couple of times and as an result I still have one ref cursor.
    Example:
    /* Determine if project is main project, then select all subprojects */
    for i in isMainProject loop
    if i.belongstoprojectno is null then
    for i in ProjectSubNumbers loop
    if ProjectSubNumbers%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    else
    for i in ProjectNumber loop
    if ProjectNumber%rowcount=1 then
    SqlStatement := InitialStatement || i.projectno;
    else
    SqlStatement := SqlStatement || PartialStatement || i.projectno;
    end if;
    end loop;
    end if;
    end loop;
    /* Open ref cursor */
    open sql_output for SqlStatement;
    Thanks in advance,
    Jeroen Muis
    KCI Datasystems BV
    mailto:[email protected]

    Example for 'dynamic' ref cursor - dynamic WHERE
    (note that Reports need 'static' ref cursor type
    for building Report Layout):
    1. Stored package
    CREATE OR REPLACE PACKAGE report_dynamic IS
    TYPE type_ref_cur_sta IS REF CURSOR RETURN dept%ROWTYPE; -- for Report Layout only
    TYPE type_ref_cur_dyn IS REF CURSOR;
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn;
    END;
    CREATE OR REPLACE PACKAGE BODY report_dynamic IS
    FUNCTION func_dyn (p_where VARCHAR2) RETURN type_ref_cur_dyn IS
    ref_cur_dyn type_ref_cur_dyn;
    BEGIN
    OPEN ref_cur_dyn FOR
    'SELECT * FROM dept WHERE ' | | NVL (p_where, '1 = 1');
    RETURN ref_cur_dyn;
    END;
    END;
    2. Query PL/SQL in Reports
    function QR_1RefCurQuery return report_dynamic.type_ref_cur_sta is
    begin
    return report_dynamic.func_dyn (:p_where);
    end;
    Regards
    Zlatko Sirotic
    null

  • Need Help: Using Ref Cursor in ProC to call a function within a Package

    I'm calling a function within a package that is returning a REF CURSOR.
    As per the Oracle Pro*C Programmer's Guide, I did the following:
    1) declared my cursor with a: EXEC SQL BEGIN DECLARE SECTION and declared the cursor as: SQL_CURSOR my_cursor;
    2) I allocated the cursor as: EXEC SQL ALLOCATE :my_cursor;
    3) Via a EXEC SQL.....END-EXEC begin block
    I called the package function and assign the return value to my cursor
    e.g. my_cursor := package.function(:host1, :host2);
    Now, the only difference between my code and the example given in the Pro*C Programmer's Guide is that the example calls a PROCEDURE within a package that passes back the REF CURSOR as an OUT host variable.
    Whereas, since I am calling a function, the function ASSIGNS the return REF CURSOR in the return value.
    If I say my_cursor := package.function(:host1, :host2); I get a message stating, "PLS-00201: identifier MY_CURSOR" must be declared"
    If I say :my_cursor := package.function(:host1, :host2); I get a message stating, "ORA-01480: trailing null missing from STR bind value"
    I just want to call a package function and assign the return value to a REF CURSOR variable. There must be a way of doing this. I can do this easily in standard PL/SQL. How can this be done in Pro*C ???
    Thanks for any help.

    Folks, I figured it out. For those who may face this problem in the future you may want to take note for future reference.
    Oracle does not allow you to assign the return value of a REF CURSOR from a FUNCTION ( not Procedure - - there is a difference) directly to a host variable. This is the case even if that host variable is declared a CURSOR variable.
    The trick is as follows: Declare the REF CURSOR within the PL/SQL BEGIN Block, using the TYPE statement, that will contain the call to the package function. On the call, you then assign the return REF CURSOR value that the function is returning to your REF CURSOR variable declared in the DECLARE section of the EXEC SQL .... END-EXEC PL/SQL Block.
    THEN, assign the REF CURSOR variable that was populated from the function call to your HOST cursor varaible. Then fetch this HOST Cursor variable into your Host record structure variable. Then you can deference individual fields as need be within your C or C++ code.
    I hope this will help someone facing a deadline crunch. Happy computing !

  • Need help about ref cursor using like table

    Hi Guys...
    I am devloping package function And i need help about cursor
    One of my function return sys_refcursor. And the return cursor need to be
    join another table in database . I don't have to fetch all rows in cursor
    All i need to join ref cursor and another table in sql clause
    like below
    select a.aa , b.cc form ( ref_cursor ) A, table B
    where A.dd = B.dd
    I appeciate it in advance

    My understanding is that you have a function that returns a refcursor and is called by a java app.
    Because this is a commonly used bit of code, you also want to reuse this cursor in other bits of sql and so you want to include it like table in a bit of sql and join that refcursor to other tables.
    It's not as easy as you might hope but you can probably achieve this with pipelined functions.
    Is it a direction that code should be going down? yes, eventually. I like the idea of pulling commonly used bits of code into a SQL statement especially into the WITH section, provided it could be used efficiently by the CBO.
    Is it worth the effort given what you have to do currently to implement it? possibly not.
    what else could you do? construct the sql statement independently of the thing that used it and reuse that sql statement rather than the refcursor it returns?
    Message was edited by:
    dombrooks

  • Need help with Ref Cursor

    Dear All,
    Version : '11.2.0.2.0'
    I have a procedure which gets called from a screen ( on .Net) if use pushes a particular button.
    The procedure takes 15 minutes to complete.
    My requirement is to intimate the front end(.Net) as soon as the procedures gets called successfully without waiting for its completion as it is going to take 15 mins.
    The reason being, the front end will popup a message saying that " The process is going to take long time, A mail will be sent to u after its completion"  once it has been intimated that the procedure has been called successfully.
    Could you please suggest can i return a cursor to front end without even manipulating the data.
    i hope my question is understandable.

    9876564 wrote:
    Dear All,
    Version : '11.2.0.2.0'
    I have a procedure which gets called from a screen ( on .Net) if use pushes a particular button.
    The procedure takes 15 minutes to complete.
    My requirement is to intimate the front end(.Net) as soon as the procedures gets called successfully without waiting for its completion as it is going to take 15 mins.
    The reason being, the front end will popup a message saying that " The process is going to take long time, A mail will be sent to u after its completion"  once it has been intimated that the procedure has been called successfully.
    Could you please suggest can i return a cursor to front end without even manipulating the data.
    i hope my question is understandable.
    It seems to me that your problem is not an Oracle one, but a user interface one.
    I'm assuming the slowness of the procedure is due to how long it's taking to query the data, and if you can't speed that up then, to have the procedure return a ref cursor, the connection between the front end and the procedure must be maintained (the process on Oracle must belong to a session, and the front end needs to be connected to that session).
    So, you can't have Oracle go off and start a seperate process and then pass back the ref cursor when it's finished, because even though you can spawn off seperate processes such as using DBMS_JOB or DBMS_SCHEDULER, they will run in their own 'session' and the calling code won't keep a hold on any of those sessions... they're effectively stand-alone and seperate.
    What you'll have to do is likely get your .net application to spawn off a child process to the main app, that presents the message saying it'll take some time, does the call to Oracle and waits for Oracle to return the resultant ref cursor, which it can then pass back to the main application etc.  Due to .net allowing for multi-tasking, that is where the split processing should take place.

  • Ref Cursor-Help Needed

    I am tryin to create a procedure with ref cursor. It is giving error message like
    PLS-00201:identifier 'TYPES>CURSOR_TYPE' must be declared.
    Any idea how to resolve this error.
    CREATE OR REPLACE PROCEDURE "PROC_GET_USERNAME" (
    p_user_name IN bmf_users_temp.user_name%TYPE,
    p_recordset OUT TYPES.cursor_type --"SYS_REFCURSOR"
    AS
    BEGIN
    OPEN p_recordset FOR
    select first_name ||' ' || last_name ||' '|| bmf_user_type ||' '||
    bmf_user_role || ' ' ||bmf_user_status from bmf_users_temp ab where
    user_name=p_user_name and
    bmf_user_status='A';
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    END PROC_GET_USERNAME;
    /

    I guess TYPES is a package in which you have declared cursor_type as a sys_refcursor.
    1. Please check the package if it has cursor_type declared as the same spelling.
    2. Check if current user have the select rights of the package TYPES.
    Regards
    G

  • Help on CAST function, defining TYPE TABLE and using a REF cursor

    Hi,
    I have written a procedure (lookup) inside a package (lookup_pkg) as shown below.
    Procedure has an output variable of type PL/SQL TABLE which is defined in the package.
    I want to write a wrapper procedure lookupref to the procedure lookup to return a ref cursor.
    CREATE OR REPLACE PACKAGE lookup_pkg AS
    TYPE t_lookup_refcur IS REF CURSOR;
    CURSOR c_lookup IS
         Select columns1,2,3,....100
                   FROM A, B, C, D, E
                   WHERE ROWNUM < 1;
    TYPE t_lookup IS TABLE OF c_lookup%ROWTYPE;
    Procedure lookup(id Number, o_lookup OUT t_lookup);
    End lookup_pkg;
    CREATE OR REPLACE PACKAGE BODY lookup_pkg As
    Procedure lookup(id Number, o_lookup OUT t_lookup) IS
    BEGIN
    END lookup;
    Procedure lookupref(id Number, o_lookupref OUT t_lookup_refcur) IS
    o_lookup t_lookup;
    BEGIN
    lookup(id, o_lookup t_lookup);
    OPEN t_lookup_refcur FOR
    SELECT *
         FROM TABLE(CAST(o_lookup AS t_lookup));
    Exception
    End lookupref;
    END lookup_pkg;
    When I compile this procedure, I am getting invalid datatype Oracle error and
    cursor points the datatype t_lookup in the CAST function.
    1. Can anyone tell me what is wrong in this. Can I convert a PL/SQL collection (pl/sql table in this case) to PL/SQL datatype table or does it need to be a SQL datatype only (which is created as a type in database).
    Also, to resolve this error, I have created a SQL type and table type instead of PL/SQL table in the package as shown below.
    create or replace type t_lookuprec as object
                   (Select columns1,2,3,....100
                   FROM A, B, C, D, E
                   WHERE ROWNUM < 1);
    create or replace type t_lookup_tab AS table of t_lookuprec;
    CREATE OR REPLACE PACKAGE BODY lookup_pkg As
    Procedure lookup(id Number, o_lookup OUT t_lookup) IS
    BEGIN
    END lookup;
    Procedure lookupref(id Number, o_lookupref OUT t_lookup_refcur) IS
    o_lookup t_lookup;
    BEGIN
    lookup(id, o_lookup t_lookup);
    OPEN t_lookup_refcur FOR
    SELECT *
         FROM TABLE(CAST(o_lookup AS t_lookup_tab));
    Exception
    End lookupref;
    END lookup_pkg;
    When I compile this package, I am getting "PL/SQL: ORA-22800: invalid user-defined type" Oracle error and
    points the datatype t_lookup_tab in the CAST function.
    2. Can anyone tell me what is wrong. Can I create a type with a select statement and create a table type using type created earlier?
    I have checked the all_types view and found that
    value for Incomplete column for these two types are YES.
    3. What does that mean?
    Any suggestions and help is appreciated.
    Thanks
    Srinivas

    create or replace type t_lookuprec as object
    (Select columns1,2,3,....100
    FROM A, B, C, D, E
    WHERE ROWNUM < 1);You are correct that you need to use CREATE TYPE to use the type in SQL.
    However unless I am mistaken you appear to have invented your own syntax for CREATE TYPE, suggest you refer to Oracle documentation.

  • "java.sql.SQLException: Ref cursor is invalid" - Please help

    Hi everyone,
    I'm really having problem. I'm surrently calling a PL/SQL stored procedure from Java but I'm getting the following error:
    java.sql.SQLException: Ref cursor is invalid
    The procedure has 2 normal IN parameters and 1 ref cursor OUT parameter. Depending upon Parameter 1 a ref cursor may or may not be initialised.
    If Parameter 1 is "yes" then a ref cursor is called to retrieve some data and passed into the OUT. If Parameter 1 is set to "no" then the ref cursor is not initialised. It is here where the error is being hrown. Does anyone know why? Microsoft ADO doesn't seem to complain. Please help is needed. Thanks in advance.
    John

    Hi Justin,
    Thanks for replying. The Java code is a bit awkward to send because we're using several "home-made" wrapper objects to call SQL and stored procedures. In both cases I create a resultset object and only this one object is used irrespective if the first parameter is "yes" or "no", but a ref cursor is passed to the OUT parameter only on condition yes. Hence, the PL/SQL code takes the form similar to:
    OPEN curs FOR SELECT * FROM table;
    The "curs" is then put into the OUT of the procedure. When the parameter is "no" then the "curs" ref cursor in the PL/SQL procedure isn't even initialised like the above. At this point Java complains of an invalid ref cursor. I can try and piece togather the code but it may be very tricky.
    John

  • DB proc - do you need to create a table to pass a ref cursor record type?

    I want to pass a limited selection of columns from a large table through a DB procedure using a REF CURSOR, returning a table rowtype:
    CREATE OR REPLACE package XXVDF_XPOS_DS021_ITEMS AS
         TYPE XXVDF_XPOS_DS021_ITEM_ARRAY
         IS REF CURSOR
         return XXVDF_XPOS_DS021_ITEM_TABLE%ROWTYPE;
    Do I need to create this dummy table?
    I can't get a TYPE to work, where the type is an OBJECT with the desired columns in it.
    So a dummy empty table will sit in the database...
    Is there another way?
    thanks!

    You can use RECORD type declaration:
    SQL> declare
      2   type rec_type is record (
      3    ename emp.ename%type,
      4    sal emp.sal%type
      5   );
      6   type rc is ref cursor return rec_type;
      7   rc1 rc;
      8   rec1 rec_type;
      9  begin
    10   open rc1 for select ename, sal from emp;
    11   loop
    12    fetch rc1 into rec1;
    13    exit when rc1%notfound;
    14    dbms_output.put_line(rec1.ename || ' ' || rec1.sal);
    15   end loop;
    16   close rc1;
    17  end;
    18  /
    SMITH 800
    ALLEN 1600
    WARD 1250
    JONES 2975
    MARTIN 1250
    BLAKE 2850
    CLARK 2450
    SCOTT 3000
    KING 5000
    TURNER 1500
    ADAMS 1100
    JAMES 950
    FORD 3000
    MILLER 1300or use, for example, VIEW to declare rowtype:
    SQL> create view dummy_view as select ename, sal from emp;
    View created.
    SQL> declare
      2   type rc is ref cursor return dummy_view%rowtype;
      3   rc1 rc;
      4   rec1 dummy_view%rowtype;
      5  begin
      6   open rc1 for select ename, sal from emp;
      7   loop
      8    fetch rc1 into rec1;
      9    exit when rc1%notfound;
    10    dbms_output.put_line(rec1.ename || ' ' || rec1.sal);
    11   end loop;
    12   close rc1;
    13  end;
    14  /
    SMITH 800
    ALLEN 1600
    WARD 1250
    JONES 2975
    MARTIN 1250
    BLAKE 2850
    CLARK 2450
    SCOTT 3000
    KING 5000
    TURNER 1500
    ADAMS 1100
    JAMES 950
    FORD 3000
    MILLER 1300 Rgds.

  • [b]HELP-Accessing REF CURSOR (select *   from *) from OCI[/b]

    I have a stored procedure that returns a weak REF CURSOR as an out parameter. I want to access the rows that are returned, in an OCI application. I want a sample OCI program that does this. The PL/SQL code is as follows
    PACKAGE TEST_PACKAGE AS
    TYPE RCT IS REF CURSOR;
    END;
    PROCEDURE TEST_PROCEDURE (R OUT TEST_PACKAGE.RCT)
    AS
    BEGIN
    OPEN r FOR
    SELECT * FROM XXX;
    END;
    THANKS.

    Hello,
    I used in my application regular connections, I created
    CallableStatement with these connections, later I got one cursor with:
    mr = ((OracleCallableStatement)cstmt).getCursor(1)
    where mr is ResultSet and cstmt is CallableStatement.
    But, when I use the Commerce PoolConnection I get serialConnection
    and it creates serialCallableStatement and the command:
    mr = ((OracleCallableStatement)cstmt).getCursor(1)
    get the next exception:
    java.lang.ClassCastException:
    weblogic.jdbc20.rmi.SerialCallableStatement at......
    Are you working with Bea ConnectionPool
    or regular Connections?
    Thank you.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Matt Sivertson ([email protected]):
    I'm having a very strange problem with some JDBC code. Basically, there is a StoredProcedure in the DB that we call through JDBC. One of the out parameters is a REF CURSOR. My user does not have select access to the table, but the stored procedure does. When I try and get the ResultSet corresponding to that RefCursor using the OracleCallableStatement.getCursor() method, and exception gets thrown saying it cannot find the table. We checked on the database, and it is actually performing a new select statement as My user, rather than as the StoredProcedure. If we open up the permissions on the table, everything works fine, but this defeats the whole purpose of what the DBA wants.
    BTW, this same Stored Procedure works when fine when accesed through PL/SQL or SQL+. Only JDBC seems to have a problem with it. Any help is greatly appreciated.
    Matt Sivertson
    [email protected]<HR></BLOCKQUOTE>
    null

  • Ref cursor help in Reports/pl sql

    Hello , i am new to this , please help!
    From oracle forms, we have a table and one of the columns from that table returns rows and the result are like ( select name, messaging_id, listing_id from dynamic_message group_query) ..I am trying to join this table with other tables based on a group type, based on if it returns 'D' or 'S' to other groups in report.
    I am getting the following error when I uncomment the open cursor statemnt
    PLS-00455: cursor 'TEMP_GRP_REC_REFCUR' cannot be used in dynamic
    SQL OPEN statement
    This is what i have so faar:
    create or replace PACKAGE grp IS
    TYPE grp_rec IS RECORD
    (listing_id varchar2(16 ),
    messaging_id varchar2(16 ),
    name varchar2(256 ) ,
    group_number Number);
    TYPE grp_rec_refcur is REF CURSOR RETURN grp_rec;
    function grprefc(P_group_number NUMBER, P_group_type CHAR) return grp_rec_refcur;
    END;
    CREATE OR REPLACE PACKAGE BODY grp IS
    function grprefc(p_group_number Number )
    return grp_rec_refcur
    IS
    temp_grp_rec_refcur grp.grp_rec_refcur;
    v_stmt_str VARCHAR2(2000) := NULL;
    v_cov_name listing.name%TYPE := NULL;
    v_cov_mid listing.messaging_id%TYPE := NULL;
    v_cov_lid listing.listing_id%TYPE := NULL;
    v_grpnum message_group.group_number%TYPE := NULL;
    BEGIN
              v_stmt_str:='SELECT dmgq.resolved_query
              INTO v_stmt_str
              FROM dynamic_message_group_query dmgq
              WHERE dmgq.group_number = p_group_number';
    OPEN temp_grp_rec_refcur FOR v_stmt_str;
         LOOP
         FETCH temp_grp_rec_refcur INTO v_cov_lid , v_cov_mid ,v_cov_name, v_grpnum ;
         EXIT WHEN temp_grp_rec_refcur %NOTFOUND;
         END Loop;
         RETURN temp_grp_rec_refcur;
    END;
    END;
    show errors;
    if there are any examples done by someone in reoprts or if you can help me solve the above, i would higghly appreciate it .
    Thanks and Good Day!

    Maybe something like my second example "Dynamic Table in the Second Query with Oracle Reports"
    - ref cursor or "simple" query Q1, which has a column "group_type", linked to a ref cursor query Q2.
    Ref cursor query Q2 - pseudo code for function:
    CREATE OR REPLACE PACKAGE BODY grp IS
    FUNCTION A_join_B_or_A_join_C_join_D
      (p_group_type CHAR(1), p_group_number NUMBER)
      RETURN dynamic_refcur
    IS
      l_refcur dynamic_refcur;
      l_stmt_str VARCHAR2(2000) := NULL;
    BEGIN
      IF p_group_type = 'S' THEN
        -- join A and B
        OPEN l_refcur FOR
          SELECT ...
            FROM A, B
           WHERE A.x = B.y;
      ELSE -- p_group_type = 'D'
        SELECT resolved_query
          INTO l_stmt_str
          FROM dynamic_message_group_query
         WHERE group_number = p_group_number;
        -- join A, C and D (= dynamically created SELECT)
        OPEN l_refcur FOR
          'SELECT ...
             FROM A, C, (' || l_stmt_str || ') D
            WHERE A.x = C.y
              AND A.z = D.t';
      END IF;
      RETURN l_refcur;
    END;
    END; Regards,
    Zlatko

  • Need to explicity close ref cursor?

    Happy Friday. I've been trying to test out this one myself, but the results are inconclusive, sooo... Say if you declare a cursor and a ref cursor as rowtype of that cursor in the specification of a package, and in the body if you 'open cursor for', have you then got to explicity close the cursor?
    If anyone's got a query against the v$ tables that would prove/disprove the above it would be much appreciated.
    Thanks in advance.

    Oracle (aka PL/SQL engine) has a garbage collector. It will close cursor handles when that handle goes out of scope.
    So you need not close explicit cursor handles for example that is defined in a local scope (though it is good programming practice to do so), whereas you should close it when that cursor handle resides within the scope of a package's state. (i.e. defined in the package header or body as a global)
    Ref cursors otoh are special - as they have no local scope. Only session scope. So as long as that Oracle session exist, that ref cursor created in that session will exist, until explicitly closed. Why? Because ref cursors are intended to be use by the client of that session - which means that irrespective of what happens scope wise on the PL/SQL engine side, that ref cursor handle must "survive" as it can (and often is) used by the client.
    This is also the primary cause for cursor leakage. Clients (especially Java apps in my experience) use ref cursors - but forget to close them after use. The open cursor handle count quickly runs up and an ORA error results.. with the Java developers then thinking there is something wrong with Oracle and that the max number of cursor handles per session should be increased.
    PS. typing this on my home console (Windows) and not work machine (Linux), so unfortunately no SQL code snippets.. but you can have a look at the Reference Manual and look for the V$ cursor views. There is an open cursor view that lists open cursors per session - just note that garbage collection can happen at the start of the next call and not at the end of the last call.. if I recall correctly. Which at times make the results look "funny" when tracing open cursor handles.

  • Help on REF Cursors

    Hi Folks,
    When i try to run the following piece of code i get errors saying :
    PLS-0221 : emp_cursor is not a procedure or is undefined
    PLS-00382 : expression is of the wrong type
    can you please help me figure out what is going wrong here ?
    Thanks very much in advance.
    Moses.
    declare
    /* REF Cursor for employee */
    emp_rec employee%ROWTYPE;
    TYPE EmpCurTyp IS REF CURSOR RETURN emp_rec%TYPE;
    emp_cursor EmpCurTyp;
    emp_id NUMBER;
    cursor dept_cursor is
    select distinct dept_id from dept;
    dept_rec dept_cursor%ROWTYPE;
    dep_id VARCHAR2(20);
    begin
    /* dept loop */
    for dept_rec in dept_cursor
    loop
    dep_id := dept_rec.dept_id;
    /* get employees for this dept */
    OPEN emp_cursor FOR
    select distinct emp_id from employee
    where dept_id = dep_id;
    /* employee loop */
    for emp_rec in emp_cursor
    loop
    emp_id := emp_rec.employee_id;
    '

    Hi Moses,
    looking at Yr code, I guess that the problem may be that You OPEN emp_cursor and after that You reopen the same cursor with the FOR statement.
    Try rewriting the LOOP in this way:
    OPEN emp_cursor FOR
    SELECT DISTINCT emp_id
    FROM employee
    WHERE dept_id = dep_id;
    FETCH emp_cursor INTO emp_record
    WHILE emp_cursor%FOUND
    LOOP
    -- Yr code here
    FETCH emp_cursor INTO emp_record;
    END LOOP;
    CLOSE emp_cursor;You can also convert the usage of the REF syntax using cursor variables.
    Hope thi helps
    Bye Max
    null

Maybe you are looking for

  • New install not accessing existing library on D: drive.

    My iTunes library is much larger than my entire SSD I use as a boot volume, so of course I keep it on a second internal hard drive labeled D:. I just had my system corrupted and all backcup images not read by restore discs, so I had to wipe my C: SSD

  • User Exit for Changing Quantity in Process Order , COR1, COR2

    Hi All, Can anyone point me towards the light in User exit related to COR1 and COR2.After the Creation of Process order  while saving i need to write a code that rounds off the quantity values. I tried to change the values in the below user exits but

  • I would like to move LiveCycle to a new computer

    Hello, I have inherited LiveCycle duties at my company.  The person who the license is assigned to is no longer with the company.  I have the serial number for the product and would like to remove it from the system that it is on currently and instal

  • Differences between "organizing" in LR3 or 4 and PSE8.

    I am considering moving to LR4 from PSE 8 because I assume that LR is a more stable and robust environment.   Over the next 3-4 months I wil be adding approx 7-10K images to PSE 8 which I'm running now. I use PSE 8 probably 90% for organizing, taggin

  • Skype to Go to Skype account

    I am supposed to be able to set up Skype to go to call a skype account from a telephone. While this works in most cases, it will not recognize Skype ids starting with "live:" (accounts originally created when Skype started accepting Microsoft account