Reg reference cursor

First time i am using reference cursors. My question is shall i use cursor For loop for reference cursor inorder to fetch the records. I have defined like this?
lsql varchar2(1000);
TYPE L_CurType IS REF CURSOR;
mm_cursor L_CurType;
begin
open mm_cursor for lsql;
For v_record in mm_cursor loop
end loop;
what's wrong in this code? I am getting error at For loop statement after open statement.

Reference cursors are used for passing a result set to a client, they are not much use in PL/SQL.
Re: Testing a procedure that returns 2 REF CURSORs
In databases that are designed for set based processing, loops should be avoded unless you enjoy solving performance problems.
The performance problems caused by using loops in database code can usually be solved by rewriting the code to use set based processing, such as SQL updates, inserts and deletes, instead of a loop.

Similar Messages

  • Using Reference Cursor Performance Issue in Report

    Hi,
    Are reference cursor supposed to be faster than a normal query? The reason why I am asking is because I am using a reference cusor query in the data model and it has a performance issue on the report, it's taking quite a while to run than If I just run the same reference cursor query in sql*plus. The difference is significantly big. Any input is very much appreciated!
    Thanks,
    Marilyn

    From the metalink bug 4372868 on 9.0.4.x. It was fixed on 10.1.2.0.2 and does not have a backport for any 9.0.4 version.
    Also the 9.0.4 version is already desupported. Please see the note:
    Note 307042.1
    Topic: Desupport Notices - Oracle Products
    Title: Oracle Reports 10g 9.0.4 & 9.0.4.x
    Action plan:
    If you are still on 9.0.4 and later version of oracle reports and have no plan yet to migrate to 10.1.2.0.2 version use the same query you are using in your reference cursor and use it as a plain SQL query in your reports data model.

  • Stored procedure with multiple Reference Cursors

    In Sybase and SQLServer, result sets are returned to the application implicitly. Oracle emulates this by passing back weak reference cursors to the application through an IN OUT parameter.The number of reference cursors must match the number of results sets. For example, if 2 select statements are present in the stored procedure code, then 2 reference cursors are passed back.The Oracle Migration Workbench creates the correct number of reference cursors but assigns each select statement results to the first cursor created. Therefore only the last set of results are returned to the client.
    Before (SQLServer)
    CREATE PROCEDURE get_sch_associated_appointment_info (@piAcc_itn int) AS SELECT s.acc_itn, r.internal_key, r.mnemonic, r.descp, sh.start_dtime, sh.end_dtime FROM schdtl s, schdtlhdr sh, resource r WHERE s.acc_itn = @piAcc_itn and sh.acc_itn = @piAcc_itn and sh.resource_itn = r.internal_key SELECT sdcr.acc_itn, sdcr.rsch_dtime, sdcr.rsch_by_init, sdcr.rsch_code, sdcr.rsch_reason, sdcr.cncl_dtime, sdcr.cncl_by_init, sdcr.cncl_code, sdcr.cncl_reason, sdcr.prev_start_dtime, sdcr.prev_by_init FROM schdtl_canrsch sdcr WHERE sdcr.acc_itn = @piAcc_itn SELECT sdi.acc_itn, i.sched_notes, i.post_sched_notes, d.pre_sch_notes, d.post_sch_notes, i.detail_key, i.output_notes FROM schdtl_info sdi, extitem i, dept d WHERE sdi.acc_itn = @piAcc_itn and sdi.actual_dept = i.dept and sdi.actual_proc_no = i.proc_no and sdi.actual_dept = d.dept
    After (Migration Workbench) – Optional Section
    CREATE OR REPLACE PROCEDURE get_sch_associated_appointment_info (piAcc_itn int, RC1 IN OUT Omwb_emulation.globalPkg.RCT1) AS OPEN RC1 SELECT s.acc_itn, r.internal_key, r.mnemonic, r.descp, sh.start_dtime, sh.end_dtime FROM schdtl s, schdtlhdr sh, resource r WHERE s.acc_itn = piAcc_itn and sh.acc_itn = piAcc_itn and sh.resource_itn = r.internal_key; OPEN RC1 SELECT sdcr.acc_itn, sdcr.rsch_dtime, sdcr.rsch_by_init, sdcr.rsch_code, sdcr.rsch_reason, sdcr.cncl_dtime, sdcr.cncl_by_init, sdcr.cncl_code, sdcr.cncl_reason, sdcr.prev_start_dtime, sdcr.prev_by_init FROM schdtl_canrsch sdcr WHERE sdcr.acc_itn = piAcc_itn; OPEN RC1 SELECT sdi.acc_itn, i.sched_notes, i.post_sched_notes, d.pre_sch_notes, d.post_sch_notes, i.detail_key, i.output_notes FROM schdtl_info sdi, extitem i, dept d WHERE sdi.acc_itn = piAcc_itn and sdi.actual_dept = i.dept and sdi.actual_proc_no = i.proc_no and sdi.actual_dept = d.dept;
    After (Manual Change)
    CREATE OR REPLACE PROCEDURE get_sch_associated_appointment_info (piAcc_itn int, RC1 IN OUT Omwb_emulation.globalPkg.RCT1, RC2 IN OUT Omwb_emulation.globalPkg.RCT1, RC3 IN OUT Omwb_emulation.globalPkg.RCT1) AS OPEN RC1 SELECT s.acc_itn, r.internal_key, r.mnemonic, r.descp, sh.start_dtime, sh.end_dtime FROM schdtl s, schdtlhdr sh, resource r WHERE s.acc_itn = piAcc_itn and sh.acc_itn = piAcc_itn and sh.resource_itn = r.internal_key; OPEN RC2 SELECT sdcr.acc_itn, sdcr.rsch_dtime, sdcr.rsch_by_init, sdcr.rsch_code, sdcr.rsch_reason, sdcr.cncl_dtime, sdcr.cncl_by_init, sdcr.cncl_code, sdcr.cncl_reason, sdcr.prev_start_dtime, sdcr.prev_by_init FROM schdtl_canrsch sdcr WHERE sdcr.acc_itn = piAcc_itn; OPEN RC3 SELECT sdi.acc_itn, i.sched_notes, i.post_sched_notes, d.pre_sch_notes, d.post_sch_notes, i.detail_key, i.output_notes FROM schdtl_info sdi, extitem i, dept d WHERE sdi.acc_itn = piAcc_itn and sdi.actual_dept = i.dept and sdi.actual_proc_no = i.proc_no and sdi.actual_dept = d.dept;

    I believe you are using .NET(?). If that is the case, please post this query to the .NET Development - Crystal Reports  forum:
    SAP Crystal Reports, version for Visual Studio
    That forum is monitored by qualified technicians and you will get a faster response there.
    Thank you for your understanding,
    Ludek

  • Recursion with reference cursors

    Hi,
    I need to do a recursive SQL select in a report. Using reference
    cursors I can do dynamic SQL selects. What do I need to do if I
    must do this recursively. I run into cursor already open error
    trying to close the cursor does not help as well.
    Any ideas?
    TIA
    Srinivas

    Ok, so you know how the if- test works, and you even seem to almost understand the code you have posted (presuming your professor has written the code, right?). Good start! I like the way you post the code and ask the question can it be done? It is far better than just writing please do my homework for me, because I am too lazy to do it myself...
    Have a look in your programming book and reed the chapter about loops. It should give you an idea of how to solve your assignment.
    And try posting to the right forum. This question belongs to the New To Java Technology forum. Later on you may advance to the Java Programming forum.
    Good luck!

  • Can we pass Reference cursor using dblink

    Can we pass reference cursor from one DB to another DB using DBlink?
    I feel like it is not possible because the memory structure of same will be available in other DB.
    Could you please let me know whether we can give a work around which will solve the issue.
    Regards,
    Balu

    Balu, cursor is a memory area which contains parsed SQL statement and everything needed for
    the execution of the SQL command. That, of course, is instance specific and carrying it over to another DB using db-link would make no sense whatsoever.

  • Weak and Strongly Typed Reference Cursors in Reports

    Our custom reports has been using a reference cursor. I have inherited the code and not sure why there is a need to use a reference cursor when it can be done by a simple select statements. I see no dynamic select statements passed or any special parameters to reason out for use of reference cursor in our custom reports. Prior developers had reason out the benefits of using reference cursor for performance. I tested this by running a report with reference cursor versus plain select statement and still the report that is using the plain select statement performed better (faster) than the report that has the reference cursor, there is a big difference.
    I have seen some disadvantage of using reference cursor on the reports that when there is a database object change even if the package that sourced the reference cursor has not been updated or modified the reports needs to be recompiled each time we get this error message coming from the report server queue:
      Terminated with error: <br>REP-8: Run time error in the PL/SQL development
      environment (DE). PDE-PSD001 Could not resolve reference to <Unknown Program Unit>
      while loading <Unknown> <Unknown>. REP-0008: Unexpected memory error while
      initializing preferences.In 9iAS reports prior version the error is occurring rarely. When we moved to 10.1.2.2.0 reports it appears the error occurs most often. We have made an effort to research about the issue and appears to be a bug. One suggestion is to use a strongly typed reference cursor. I have tried to researched about the difference between a weak and strongly typed reference cursor but failed to understand them. I appreciate any help about examples differentiating a weak versus a strongly typed reference cursors.
    Thanks,
    Warren

    I guess my point, for what it's worth, is that whether you use only a strongly typed REF CURSOR, or whether you also use a weakly typed REF CURSOR, you may still end up getting the REP-0008 error (at least if your report is in .REP format). You can avoid this by using a pipelined function instead (or by putting the SQL directly in the report, or possibly by using .RDF or .JSP format).
    To test this, you might:
    1. Create a database package with an SQL*Plus script that that looks something like this:
    CREATE OR REPLACE PACKAGE TEST AS
        TYPE RECORD_TYPE IS RECORD
            USERNAME ALL_USERS.USERNAME%TYPE
        TYPE TABLE_TYPE IS TABLE OF RECORD_TYPE;
        TYPE WEAKLY_TYPED_REF_CURSOR_TYPE IS REF CURSOR;
        TYPE STRONGLY_TYPED_REF_CURSOR_TYPE IS REF CURSOR RETURN RECORD_TYPE;
        FUNCTION GET_WEAKLY_TYPED_REF_CURSOR RETURN WEAKLY_TYPED_REF_CURSOR_TYPE;
        FUNCTION GET_STRONGLY_TYPED_REF_CURSOR RETURN STRONGLY_TYPED_REF_CURSOR_TYPE;
        FUNCTION GET_PIPELINED_TABLE RETURN TABLE_TYPE PIPELINED;
    END TEST;
    CREATE OR REPLACE PACKAGE BODY TEST AS
        FUNCTION GET_WEAKLY_TYPED_REF_CURSOR RETURN WEAKLY_TYPED_REF_CURSOR_TYPE
        IS
            cWeaklyTypedRefCursor WEAKLY_TYPED_REF_CURSOR_TYPE;
        BEGIN
            OPEN cWeaklyTypedRefCursor FOR
            SELECT USERNAME FROM ALL_USERS;
            RETURN cWeaklyTypedRefCursor;
        END GET_WEAKLY_TYPED_REF_CURSOR;
        FUNCTION GET_STRONGLY_TYPED_REF_CURSOR RETURN STRONGLY_TYPED_REF_CURSOR_TYPE
        IS
            cStronglyyTypedRefCursor WEAKLY_TYPED_REF_CURSOR_TYPE;
        BEGIN
            OPEN cStronglyyTypedRefCursor FOR
            SELECT USERNAME FROM ALL_USERS;
            RETURN cStronglyyTypedRefCursor;
        END GET_STRONGLY_TYPED_REF_CURSOR;
        FUNCTION GET_PIPELINED_TABLE
        RETURN TABLE_TYPE PIPELINED
        IS
        BEGIN
            FOR rec IN
                SELECT USERNAME FROM ALL_USERS
            LOOP
                PIPE ROW(rec);
            END LOOP;
        END GET_PIPELINED_TABLE;
    END TEST;
    /2. Create a report based on REF CURSOR query using only a strongly typed REF CURSOR. The PL/SQL statement that you use in the report as the data source for the query might look something like this:
    function QR_1RefCurDS return test.strongly_typed_ref_cursor_type is
    begin
      return test.get_strongly_typed_ref_cursor;
    end;3. Compile the report to a .REP file and run it to make sure it works as expected.
    4. Drop and re-create the TEST package in the database.
    5. Try running the .REP file again. I expect you will get the REP-0008 error.
    6. Modify the REF CURSOR query to use an underlying weakly typed REF CURSOR by changing the PL/SQL statement (from Step 2) to something like this:
    function QR_1RefCurDS return test.strongly_typed_ref_cursor_type is
    begin
      return test.get_weakly_typed_ref_cursor;
    end;7. Repeat Steps 3 through 5. I expect you will get the REP-0008 error again.
    8. Replace the REF CURSOR query in report with an SQL query that looks something like this:
    SELECT * FROM TABLE(TEST.GET_PIPELINED_TABLE)9. Repeat Steps 3 through 5. I expect you will not get the REP-0008 error.
    Hope this helps.

  • REFERENCE CURSOR NOT CLOSING - Urgent!!!!!!

    I have some Oracle Stored Fucntions which return REFERENCE TYPE CURSOR. I noticed they are not closing. I even tried the following , but no luck. Any help is much needed.
    PACKAGE Types
    AS
    PRAGMA SERIALLY_REUSABLE;
    TYPE ref_cursor IS REF CURSOR;
    END Types;

    Thanks Justin.
    As you have replied to my query , I am placing the next again.
    I am using the following code :
    counter = 1;
    parm_status = OCIParamGet(stmthp, OCI_HTYPE_STMT, errhp, &mypard, (ub4) counter);
    /* Loop only if a descriptor was successfully retrieved for
    current position, starting at 1 */
    while (parm_status==OCI_SUCCESS)
         /* Retrieve the data type attribute */
         OCIAttrGet((dvoid*) mypard, (ub4)OCI_DTYPE_PARAM, (dvoid*) &dtype,(ub4 *) 0, (ub4) OCI_ATTR_DATA_TYPE, (OCIError *) errhp );
    When I have a stored proc with a reference cursor open then the above code works fine. But if I close the cursor before returning from the procedure then in the above case OCIParamGet() is returning a parameter descriptor , which raises unhandled exception when being called from OCIAttrGet().
    I think as the memory got freed where the reference cursor points , oracle should return some exception that could be handled but instead I receive unhandled exception.
    Is this a problem with Oracle or I need to something else at the client side.
    Please let me know all your views.
    Regards
    Sutanu

  • Reference cursor

    anybody have knowledge about reference cursor. please share it with me

    <FONT FACE="Arial" size=2 color="2D0000">
    Start Here  
    REF CURSOR
    -SK
    </FONT>

  • Reference Cursors

    I have a function that selects data from a table (Oracle 8i) into a reference cursor and returns the reference cursor.
    After I execute this function for the first time using SQL+, I notice that the number of open cursors has increaed. The number of open cursors will only drop down to the original level after I close SQL+.
    Is there a way to explicility close a reference cursor from outside the funciton?

    But how do you securely decide if a cursor is needed any longer?
    A better way to solve your problem will be to increase the maximum of open cursors in the DBMS administration.

  • Can anybody explain in detail reference cursors?

    I couldnt understand the concept of reference cursors in details
    Regards
    shweta

    if we want use the cursor for more than one select statement then we will go for
    ref cursor.
    prior to oracle 9i it needs two statements to declare a refcursor
    ex: type t1 is ref cursor
    a t1;
    here a is of type ref cursor and called as CURSOR VARIABLE.
    in oracle 9i there is one statement is enough to declare ref cursor
    ex a sys_refcursor
    ex: declare
    a sys_refcursor;
    e emp%rowtype;
    d dept%rowtype;
    begin
    open a for select * from emp; -- 1 select statement
    loop
    fetch a into e;
    exit when a%notfound;
    dbms_output.put_line(e.empno||' '||e.ename);
    end loop;
    close a;
    open a for select * from dept; -- 2 select statement
    loop
    fetch a into d;
    exit when a%notfound;
    dbms_output.put_line(d.deptno||' '||d.dname);
    end loop;
    close a;
    end;
    regards
    venu

  • Help with Collections and Reference Cursor

    I have a procedure where I want to populate a table type and then return the results with a reference cursor so the results can be used by Hyperion. Here are the type declarations:
    create or replace type gg_audit_object as object (
                   owner varchar2(30),
                   table_name varchar2(30),
                   lag_time number)
    CREATE OR REPLACE TYPE gg_audit_table AS TABLE OF gg_audit_object
    and here's the procedure:
    CREATE OR REPLACE PROCEDURE ETSREP_GG_AUDIT_XX2 (results_cursor in out types.cursorType)
    AS
    v_owner varchar2(30);
    v_table_name varchar2(30);
    v_column_name varchar2(30);
    type v_record is record(
    owner varchar2(30),
    table_name varchar2(30),
    lag_time number);
    r1 v_record;
    t1 gg_audit_table;
    table_cr types.cursorType;
    sql_stmt varchar2(5000);
    cursor table_select is
    select g.owner,
    g.table_name,
    g.column_name
    from gg_tables_to_audit g
    where g.active_ind = 'Y'
    order by 1,2;
    BEGIN
    rec_count := 0;
    for main_rec in table_select loop
    sql_stmt := '';
    v_owner := main_rec.owner;
    v_table_name := main_rec.table_name;
    v_column_name := main_rec.column_name;
    sql_stmt := 'select '
    || '''' || v_owner || ''','
    || '''' || v_table_name || ''','
    || 'sysdate - max(' || v_column_name || ') '
    || 'from ' || v_owner || '.' || v_table_name;
    open table_cr for sql_stmt;
    FETCH table_cr into r1;
    close table_cr;
    -- here's where I'm stumped. I need to take the values from r1 and put them
    -- into t1.
    -- Something like this (or whatever is the correct way to do it)
    -- insert into table(t1) values (r1.owner, r1.table_name, r1.lag_time);
    end loop; -- end table_select loop
    -- and then open a reference cursor and select them out of t1.
    -- Something like
    -- open results_cursor for select * from t1;
    END;
    Just trying to avoid creating a real table and populating that. Any guidance would be greatly appreciated.

    Found the perfect example on Ask Tom. Here is the solution.
    create or replace package GG_AUDIT
    as
    type rc is ref cursor;
    procedure GG_AUDIT_PROC( r_cursor in out types.cursorType );
    end;
    create or replace package body GG_AUDIT
    as
    procedure GG_AUDIT_PROC( r_cursor in out types.cursorType )
    is
    l_data gg_audit_table := gg_audit_table();
    table_cr types.cursorType;
    type v_record is record(
    owner varchar2(30),
    table_name varchar2(30),
    lag_time number);
    r1 v_record;
    sql_stmt varchar2(5000);
    v_owner varchar2(30);
    v_table_name varchar2(30);
    v_column_name varchar2(30);
    rec_count number := 0;
    cursor table_select is
    select g.owner,
    g.table_name,
    g.column_name
    from gg_tables_to_audit g
    where g.active_ind = 'Y'
    order by 1,2;
    begin
    for main_rec in table_select loop
    sql_stmt := '';
    v_owner := main_rec.owner;
    v_table_name := main_rec.table_name;
    v_column_name := main_rec.column_name;
    sql_stmt := 'select '
    || '''' || v_owner || ''','
    || '''' || v_table_name || ''','
    || 'sysdate - max(' || v_column_name || ') '
    || 'from ' || v_owner || '.' || v_table_name;
    open table_cr for sql_stmt;
    FETCH table_cr into r1.owner, r1.table_name, r1.lag_time;
    close table_cr;
    rec_count := rec_count + 1;
    l_data.extend;
    l_data(rec_count) := gg_audit_object(r1.owner, r1.table_name, r1.lag_time);
    end loop;
    open r_cursor for select * from TABLE ( cast ( l_data as gg_audit_table) );
    end; -- end procedure
    end;
    Works perfectly. Thanks guys.

  • How to get query text from reference cursor

    Oracle 9.2.0.5
    create or replace procedure test3
    is
       lcur sys_refcursor;
       lquery varchar2(2000);
    begin
       OPEN lcur FOR
          SELECT CONTRACT_ID FROM CONTRACT;
       lquery := lcur.Query;     -- <= Pseudocode           
    end;Basically, if someone passes a reference cursor, how can I get the "text" of the cursor. I want to pass it to DBMS_DESCRIBE.PARSE...so that I eventually call DBMS_SQL.DESCRIBE_COLUMNS.
    Thanks,
    Jason

    Do you have a code example?
    Ideally, I'd like to use Pl/SQL only, but if I have to do it in Java, I will.
    Thanks,
    Jason

  • Reg Open Cursor Concept

    Friends,
    Please kindly help me to analyse this dump.
    In BI end routine select * query has been written to fetch values from active dso . They are using non primary key in the where condition.
    More than 2 crore 20 million records were avaialble in that DSo for that condtion. While executing this query its going to dump.
    If i move ahead with Open cursor set Hold will this query work fine and using open cursor set hold can i fetch  2 crore 20 million records.
    In dump its shwoing to check the parameters : ztta/roll_area  ,ztta/roll_extension and abap/heap_area_total . Even i checked those parametrs in RZ11. The curent val is sufficient.
    Please kindly advice me for this dump and will open cursor set hold avoid the dump for  2 crore 20 million  records.
    Thanks
    Edited by: Suhas Saha on Sep 29, 2011 1:06 PM

    I am not completely convinced:  the difference depends on the task which has to be done with the records of a package.
    If the records are processed and the result must be written to the database into another table, then it will be necessary to COMMIT the changes, otherwise the 20.000.000 records will cause an overflow in the redo-logs of the database.
    => Only the OPEN CURSOR WITH HOLD will survive the DB-Commit.
    The SELECT ... PACKAGE SIZE is simpler and can be used, if the result is further processed and reduced in size, which makes it possible to keep all data in memory (no intermediate DB-COMMITs are necessary) .
    I would assume that case is the less frequent use case.
    Siegfried

  • Default value for a reference cursor argument to a package function

    I'm trying to do the following to allow the caller to pass in a ref cursor arg or a SrcTextID (internal). Anyway, I'm just trying to use defaults, rather than overloading the routine, but I can't figure out how to default a ref cursor variable.
    FUNCTION f_execute_query_and_build_file(
         bn_debug_mode_in                              IN           common_func.BOOLEAN_NUMBER,
         n_ahs_file_definition_id_in          IN           AHS_FILE_DEFINITION.AHS_FILE_DEFINITION_ID%TYPE,
         lst_ordered_column_names               IN           common_func.STRING_TABLE,
         s_file_directory_in                         IN           VARCHAR2 := null,
         s_file_name_in                                   IN           VARCHAR2 := null,
         n_src_text_query_id_in                    IN           SRC_TEXT.SRC_TEXT_ID%TYPE := Null,
         refcur_query_in                              IN           sys_refcursor := Null,
         s_error_msg_out                                   OUT      common_func.T_ERROR_MSG )
    RETURN NUMBERThis causes a "PLS-00382 expression is of wrong type" msg. Okay, so fine. Then I thought that I would declare a package level "empty" ref cursor to act as "empty" default...which causes a "PLS-00994 Cursor Variables cannot be declared as part of a package" msg.
    Any ideas?
    Thanks,
    Jason

    in 10g you can...Unfortunately 9i doesn't like it:
    scott@ORA92> DECLARE
      2    variable_name SYS_REFCURSOR := NULL;
      3  BEGIN
      4    NULL;
      5  END;
      6  /
      variable_name SYS_REFCURSOR := NULL;
    ERROR at line 2:
    ORA-06550: line 2, column 34:
    PLS-00382: expression is of wrong type
    ORA-06550: line 2, column 17:
    PL/SQL: Item ignored
    scott@ORA92> DECLARE
      2    PROCEDURE procedure_name (
      3        parameter_name IN SYS_REFCURSOR := NULL)
      4    IS
      5    BEGIN
      6        NULL;
      7    END;
      8  BEGIN
      9    procedure_name;
    10  END;
    11  /
        parameter_name IN SYS_REFCURSOR := NULL)
    ERROR at line 3:
    ORA-06550: line 3, column 40:
    PLS-00382: expression is of wrong type
    ORA-06550: line 2, column 3:
    PL/SQL: Item ignored
    ORA-06550: line 9, column 3:
    PLS-00306: wrong number or types of arguments in call to 'PROCEDURE_NAME'
    ORA-06550: line 9, column 3:
    PL/SQL: Statement ignored
    Barbara what is the difference between 'DEFAULT' and
    ':=' in parameter declarations?Apparently there is no difference. My mistake. I have always used default. Somewhere along the way I obtained the misimpression that using := would overwrite a passed value, similar to the way it would when used between is/as and begin, whereas default would only use the default value if another value was not passed. I don't recall where I got that idea. The test below shows that my presumption was wrong:
    scott@ORA92> CREATE OR REPLACE PROCEDURE test
      2    (p_1 IN VARCHAR2 DEFAULT 'default value for p_1',
      3       p_2 IN VARCHAR2 := 'defualt value for p_2')
      4  AS
      5  BEGIN
      6    DBMS_OUTPUT.PUT_LINE (p_1);
      7    DBMS_OUTPUT.PUT_LINE (p_2);
      8  END test;
      9  /
    Procedure created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> SET SERVEROUTPUT ON
    scott@ORA92> EXECUTE test ('passed value for p_1', 'passed value for p_2')
    passed value for p_1
    passed value for p_2
    PL/SQL procedure successfully completed.
    scott@ORA92>

  • Very slow if reference cursor value in another query

    I have a script like below:
    declare
    CURSOR c1 IS
    select rptd_by, total from (select rptd_by, count(rptd_by) total from LOCBUG_ALL_M group by rptd_by order by count(rptd_by) desc) where rownum < 2;
    begin
    FOR item IN c1 LOOP
    select count(*) into bug_num from locbug_all_m h, v_nbtbug b where (h.rptd_by like item.rptd_by) and (b.nls_related=7) and (h.rptno=b.bugdb_num);
    -- 6 more similar query
    END LOOP;
    end;
    It takes nearly 4 minutes to run.
    If in the loop, I change the item.rptd_by to a static value, it only takes less than 5 seconds.
    The query used for cursor only takes 0.02 second to run.
    Why there's such difference? How can I solve this problem? I'm running this script in HTMLDB and it could timeout if it takes minutes to run.

    What are you really trying to select in the loop?
    SQL> select * from locbug_all_m;
    RPTD_BY          COL2
    X1                  1
    X2                  2
    X3                  3
    X4                  4
    X5                  5
    X6                  6
    X7                  7
    X8                  8
    X9                  9
    X10                10
    X                  11
    11 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  select count(*) from locbug_all_m
      2* where rptd_by like 'X'
    SQL> /
      COUNT(*)
             1
    SQL> ed
    Wrote file afiedt.buf
      1  select count(*) from locbug_all_m
      2* where rptd_by like 'X%'
    SQL> /
      COUNT(*)
            11
    SQL> select count(*) from locbug_all_m
      2  where rptd_by = 'X';
      COUNT(*)
             1

Maybe you are looking for

  • Why cannot I open NEF files from a Nikon D600 with Photoshop CS5?

    When I try to open raw NEF files from a Nikon D600 with Photoshop CS5 I get: "Could not complete your request because the file appears to be from a camera model which is not supported by the installed version of Camera Raw" Nikon D600, however, is am

  • Using Windows 7...where is the iPhone Backup File Location?

    K...Im trying to burn a CD of the Data have for my iPhone 3GS so next time I restore from a different computer i can always have my files with me...where do i find it?

  • Access control in workflow tasks

    I want to filter which users should have access to a certain workflow task. If looking in the help file there should be some way to filter the users which should be granted access. But this functionality seems to be switched off. Can anybody tell me

  • Dragging images in PS Elements 3

    In the past few months I have been happily dragging my photos from the Oganiser to elements 3 to edit, then dragging them to a new canvas to be re sized, creating a page with multiple images of various sizes. Now when I try to do the same thing I get

  • Can Anyone guide me?

    Hi there, I have an imac that I brought and when I did, I brought iworks CD which I have been using on my machine. Anyway, recently I brought an ipad 4 and wanted to use iworks on there and was told that as I have it on my mac, i have no need to buy