OPENING REF CURSOR

Hi,
I have a question on reference cursor. In case of having the data from a database table , can the ref cursor be open for a pl/sql table or a pl/sql object . The scenario is something like this . I have a report which needs some calculations and analysis , for each column . To have this, the data must be processed and put in a temp table . As Oracle report can be based on reference cursor instead of database table I dont want to use temp tables ( also against my company policy). So if the recursor can be based on a pl/sql table or a plsql object then i can have all the precess in a package , put the processed data on the pl/sql table or object and have the reference cursor get the data from there . Build the report on the reference cursor. Is it possible ? I tried a statement like this
OPEN v_cursor FOR SELECT * FROM v_tab;
Here V_Tab is a PL?SQL table. And it gave me an error message that "identifier v_tab must be decalred", because its treating v_tab as a database table. What to do ?
Thanks
Feroz

Hello
In your forms builder Online help search for 'Creating a Data Block from a Procedure that Uses a Ref Cursor'. It provides a pretty good example.
cheers
Q

Similar Messages

  • Open ref cursor in a procedure

    Hi
    I have a procedure which has 3 input parameters and 1 REF CURSOR type OUT parameter.
      In the body of the procedure a select query is dynamically being created, and just before the end of the procedure the REF CURSOR is opened for SELECT(dynamic) query
    For Ex: Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
    decalre
      strQry varchar2(3000);
    begin
       -- strQry is select query built dynamically
    OPEN RETVAL for strQry;
    end proc_name;
    This procedure is being called by a java application. My question is what the open cursor statement is doing in the procedure?
    Any ideas? Thanks!
    greddy

    Hi,
    As i know, for example if we want to generate a report for some particular records in our project.consider we are using java as front end and oracle as backend. ok. In that case we need to bring the data from backend to front end ,for that in backend (oracle) we can write procedure to perform this task using ref cursors.
    Note: ref cursor will provide the most efficient way in bringing the records from back end to front end.
    Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
    decalre
    strQry varchar2(3000);
    begin
    -- strQry is select query built dynamically
    --if we are using dynamic query, we can filter out the records using id or name or date
    once we did, we need to pass the values to calling enviroment, since we declared the ref cursor as out parameter, we can use the ref cursor to pass the values to calling enviroment. Since we are using ref cursor we need to open the cursor for that dynamic query.
    OPEN RETVAL for strQry;
    end proc_name;
    hope this information is some what helpful. if you got any details regarding this please post it..
    thanks.

  • Opening Ref Cursor in Forms 10

    Hi,
    I have a procedure test which returns refcursor as out parameter. How can I open and process this refcursor in forms to poulate a non base table block ?
    Regards,
    Rajesh

    Hello
    In your forms builder Online help search for 'Creating a Data Block from a Procedure that Uses a Ref Cursor'. It provides a pretty good example.
    cheers
    Q

  • 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

  • Ref Cursor - How to append records into ref cursor?

    Hi,
    Is it possible to append ref cursor?
    Iam having a procedure which accepts 1 string as input
    parameter. That string will have list of ID delimited by comma.
    I want to extract & match every ID with some tables.
    My problem is for first ID i would get 10 records
    and for 2nd ID i 'l get other 20 records. But while returning
    i need to send the same(10 + 20 records) as ref cursor(OUT parameter).
    But in below given code i could send only last 20 records. first
    10 records are not append/updated into ref cursor.
    How to append 2nd 20 records with 1st 10 records? so that i can
    send all the 30 records.
    Here goes my code...
    CREATE OR REPLACE PROCEDURE getCRMGroupsAndRollups_PRC
    in_groupId IN VARCHAR2,
    out_getCRMGroups OUT TYPES.DATASET
    IS
    v_temp VARCHAR2(500) := in_groupId ||',';
    v_temp_split VARCHAR2(500);
    v_pos1 NUMBER := 0;
    v_pos2 NUMBER := 1;
    v_pos3 NUMBER := 0;
    v_extract_char VARCHAR(1) := NULL;
    v_comma_cnt NUMBER := 0;
    BEGIN
    -- check in for null input parameters
    IF ( in_groupId IS NOT NULL ) THEN
    -- loop to count no of in_groupId
    FOR j IN 1..LENGTH(v_temp)
    LOOP
         v_extract_char := SUBSTR(v_temp,j,1);
         IF (v_extract_char = ',') THEN
              v_comma_cnt := v_comma_cnt + 1;
         END IF;     
    END LOOP;
    -- loop to extract in_group Id
    FOR i IN 1..v_comma_cnt
    LOOP
         v_pos1 := instr(v_temp,',',(v_pos1 + 1));
         v_pos3 := ((v_pos1-1) - v_pos2 )+ 1;
         v_temp_split := SUBSTR(v_temp,v_pos2,v_pos3);
         v_pos2 := v_pos1 + 1;
    -- query to return dataset filled BY list of all the current
    -- CRM groups and the associated rollup groups
    OPEN out_getCRMGroups FOR
    SELECT
    DISTINCT
    gcs.crm_st_id_cd,
    gcs.lgcy_roll_up_grp_num,
    gcs.lgcy_roll_up_grp_name,
    gcs.grp_xwalk_complt_dt,
    gcs.crm_grp_num,
    gcs.facets_gnat_id,
    gcs.crm_grp_name
    FROM
    grp_convsn_stat gcs
    --lgcy_xref_elem lxe
    WHERE
    ( gcs.mbrshp_convsn_aprvl_dt = NULL )
    OR ( gcs.mbrshp_convsn_aprvl_dt < (SYSDATE - 7 ) )
    AND ( gcs.facets_grp_stat_actv_ind = 'Y' )
    AND ( gcs.lgcy_roll_up_grp_num = v_temp_split );
    END LOOP;
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('INTERNAL ERROR');
    END getCRMGroupsAndRollups_PRC;
    in this v_temp_split will have extracted id & iam opening
    ref cursor for each & every ID extracted from list.
    2) How to handle no_data_found exception for this ref cursor?
    Please help me....
    -thiyagarajan.

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:110612348061
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:210612357425
    Message was edited by:
    Kamal Kishore

  • Ref cursor is slower than issuing the same query directly

    We are building SQL dynamically in PL/SQL procedure. SQL is complex enough (pivoting, UNIONS, spatial operations, complex underlying view joining many tables). Then we are opening ref cursor output parameter using the following syntax:
    OPEN p_cursor FOR v_sql using p_param1, p_param2;
    Then client code iterates through the rows of the cursor. It takes about a minute. If we run the SQL stored in v_sql variable directly in SQL Plus (replacing bind variables with values of course), we get 4 seconds response time.
    QUESTION: what makes ref cursor being so slow comparing with direct execution of the same query?

    OK, here are the traces. Execution plans look different. I have called SP (which opens ref cursor) first, then applied tkprof on trace file, copied SQL from that file into SQL Plus (before that I have defined bind variables in SQL Plus) and executed it, so I'm 100% sure that in SQL Plus I'm running exactly the same query SP issues for ref cursor.
    1. PL/SQL - ref cursor:
    TKPROF: Release 10.2.0.1.0 - Production on Wed May 16 10:59:30 2007
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Trace file: D:\oracle\product\10.2.0\admin\dae\udump\dae_ora_17004_refcursor.trc
    Sort options: default
    count = number of times OCI procedure was executed
    cpu = cpu time in seconds executing
    elapsed = elapsed time in seconds executing
    disk = number of physical reads of buffers from disk
    query = number of buffers gotten for consistent read
    current = number of buffers gotten in current mode (usually for update)
    rows = number of rows processed by the fetch or execute call
    BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;
    call count cpu elapsed disk query current rows
    Parse 2 0.00 0.00 0 0 0 0
    Execute 569 0.12 0.09 0 1707 0 569
    Fetch 0 0.00 0.00 0 0 0 0
    total 571 0.12 0.09 0 1707 0 569
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 75
    declare
    TYPE OutRefCursor IS REF CURSOR;
    TYPE RightClickRec IS RECORD(category_ varchar2(50), subcategory varchar2(50), param_name varchar2(50), param_value varchar2(50));
    rc OutRefCursor;
    rec RightClickRec;
    errno number;
    errmsg varchar2(200);
    begin
    cust_pck_layer.get_right_click_channel_info('7WAN097B_B','TCH',rc, errno, errmsg);
    loop
    fetch rc into rec;
    exit when rc%notfound;
    dbms_output.put_line(rec.category_ || ' ' || rec.subcategory || ' ' || rec.param_name || ' ' || rec.param_value);
    end loop;
    end;
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.15 0.15 0 0 0 1
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.15 0.15 0 0 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 75
    select Category, Sub_Category, Param_Name, Param_Value
    from
    ( ( select distinct 0 as order_c,'TCH Analysis' as Category, NULL as
    Sub_Category,0 as Param_Id, 'Analyzed Sector' as Param_Name, :p_sectorid_1
    as Param_Value, 0 as SORTORDER, 0 as DISTANCE from dual)
    UNION select
    order_c,Category,Sub_Category,Param_Id,Param_Name,stragg(Param_Value) as
    Param_Value,1 as SORTORDER, 0 as DISTANCE from ( select distinct 1 as
    order_c,'TCH Analysis' as Category, NULL as Sub_Category,0 as Param_Id,
    'TCH' as Param_Name, to_char(CHANNEL) as Param_Value, 1 as SORTORDER, 0 as
    DISTANCE from sector_freq_params where SECTOR_ID=:p_SectorId_2 and
    CHAN_TYPE_ID = 2) group by order_c,Category,Sub_Category,Param_Id,
    Param_Name,SORTORDER
    UNION (select r.rr + 1 order_c, 'TCH Analysis' as
    Category, to_char(Sub_Category) as Sub_Category,
    decode(r.rr, 1, 1, 2, 3, 3,
    3, 4, 4, 5, 4) Param_Id,
    decode(r.rr, 1, 'Sector Name', 2, 'Channel
    Number', 3, 'BSIC', 4, 'Relationship', 5, 'Distance to Sector (mi)')
    Param_Name,
    decode(r.rr, 1, SECTOR_ID, 2, Channel_Number, 3, BSIC, 4,
    Relationship, 5, Distance) Param_Value, SORTORDER, DISTANCE from
    (select
    rownum Sub_Category, SECTOR_ID, SORTORDER, Channel_Number, BSIC,
    Relationship, DISTANCE
    from dae_admin.TCH_ANALYSIS_VIEW where
    SELECTED_SECTOR_ID = :p_sectorid_3 and
    SDO_WITHIN_DISTANCE(GEOLOC,
    SELECTED_GEOLOC, 'unit=MILE,distance=25')='TRUE') qry,
    (select 1 rr from
    dual union select 2 from dual union select 3 from dual union select 4 from
    dual union select 5 from dual) r)) order by SORTORDER, DISTANCE, order_c
    asc
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 8513 31.56 33.05 0 1006398 0 8512
    total 8515 31.56 33.05 0 1006398 0 8512
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 75 (recursive depth: 1)
    Rows Row Source Operation
    8512 SORT ORDER BY (cr=1972854 pr=0 pw=0 time=62811214 us)
    8512 VIEW (cr=1972854 pr=0 pw=0 time=62806007 us)
    8512 SORT UNIQUE (cr=1972854 pr=0 pw=0 time=62797492 us)
    8512 UNION-ALL (cr=1972854 pr=0 pw=0 time=2119247 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=1 us)
    1 SORT GROUP BY (cr=2457 pr=0 pw=0 time=16606 us)
    3 VIEW (cr=2457 pr=0 pw=0 time=16040 us)
    3 HASH UNIQUE (cr=2457 pr=0 pw=0 time=16036 us)
    3 PARTITION RANGE ALL PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3999 us)
    3 TABLE ACCESS FULL SECTOR_FREQ_PARAMS PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3996 us)
    8510 MERGE JOIN CARTESIAN (cr=1970397 pr=0 pw=0 time=62768739 us)
    5 VIEW (cr=0 pr=0 pw=0 time=54 us)
    5 SORT UNIQUE (cr=0 pr=0 pw=0 time=49 us)
    5 UNION-ALL (cr=0 pr=0 pw=0 time=21 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=2 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=0 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=2 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=1 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=2 us)
    8510 BUFFER SORT (cr=1970397 pr=0 pw=0 time=62760191 us)
    1702 VIEW (cr=1970397 pr=0 pw=0 time=20797110 us)
    1702 COUNT (cr=1970397 pr=0 pw=0 time=20793704 us)
    1702 VIEW TCH_ANALYSIS_VIEW (cr=1970397 pr=0 pw=0 time=20792001 us)
    15588 HASH JOIN (cr=10465 pr=0 pw=0 time=2560803 us)
    15609 MERGE JOIN (cr=4918 pr=0 pw=0 time=1430639 us)
    478112 MERGE JOIN CARTESIAN (cr=2461 pr=0 pw=0 time=659598 us)
    1 PARTITION RANGE ALL PARTITION: 1 2 (cr=4 pr=0 pw=0 time=79 us)
    1 TABLE ACCESS BY LOCAL INDEX ROWID SECTORS PARTITION: 1 2 (cr=4 pr=0 pw=0 time=68 us)
    1 INDEX RANGE SCAN SECTORS_SECTORID_IND PARTITION: 1 2 (cr=3 pr=0 pw=0 time=25 us)(object id 1834180)
    478112 BUFFER SORT (cr=2457 pr=0 pw=0 time=181427 us)
    478112 PARTITION RANGE ALL PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=478158 us)
    478112 TABLE ACCESS FULL SECTOR_FREQ_PARAMS PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=45 us)
    15609 FILTER (cr=2457 pr=0 pw=0 time=1859879 us)
    1434336 SORT JOIN (cr=2457 pr=0 pw=0 time=513880 us)
    3 PARTITION RANGE ALL PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3966 us)
    3 TABLE ACCESS FULL SECTOR_FREQ_PARAMS PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3958 us)
    115509 PARTITION RANGE ALL PARTITION: 1 2 (cr=5547 pr=0 pw=0 time=115594 us)
    115509 TABLE ACCESS FULL SECTORS PARTITION: 1 2 (cr=5547 pr=0 pw=0 time=115586 us)
    select count(*)
    from
    mdsys.geodetic_srids where srid = 99900001
    call count cpu elapsed disk query current rows
    Parse 62352 0.53 0.47 0 0 0 0
    Execute 62353 0.78 0.76 0 0 0 0
    Fetch 62352 0.65 0.65 0 187056 0 62352
    total 187057 1.96 1.90 0 187056 0 62352
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 2)
    Rows Row Source Operation
    1 SORT AGGREGATE (cr=3 pr=0 pw=0 time=39 us)
    0 TABLE ACCESS BY INDEX ROWID SDO_CS_SRS (cr=3 pr=0 pw=0 time=24 us)
    1 INDEX UNIQUE SCAN SYS_C003941 (cr=2 pr=0 pw=0 time=14 us)(object id 48833)
    select wktext, srid
    from
    mdsys.cs_srs where srid = 99900001
    call count cpu elapsed disk query current rows
    Parse 31176 0.20 0.20 0 0 0 0
    Execute 31176 0.18 0.26 0 0 0 0
    Fetch 31176 0.20 0.23 0 93528 0 31176
    total 93528 0.59 0.71 0 93528 0 31176
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 2)
    Rows Row Source Operation
    1 TABLE ACCESS BY INDEX ROWID SDO_CS_SRS (cr=3 pr=0 pw=0 time=9 us)
    1 INDEX UNIQUE SCAN SYS_C003941 (cr=2 pr=0 pw=0 time=6 us)(object id 48833)
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 3 0.00 0.00 0 0 0 0
    Execute 570 0.28 0.25 0 1707 0 570
    Fetch 0 0.00 0.00 0 0 0 0
    total 573 0.28 0.25 0 1707 0 570
    Misses in library cache during parse: 0
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 93529 0.73 0.68 0 0 0 0
    Execute 93530 0.96 1.03 0 0 0 0
    Fetch 102041 32.42 33.94 0 1286982 0 102040
    total 289100 34.12 35.66 0 1286982 0 102040
    Misses in library cache during parse: 0
    93532 user SQL statements in session.
    0 internal SQL statements in session.
    93532 SQL statements in session.
    Trace file: D:\oracle\product\10.2.0\admin\dae\udump\dae_ora_17004_refcursor.trc
    Trace file compatibility: 10.01.00
    Sort options: default
    0 session in tracefile.
    93532 user SQL statements in trace file.
    0 internal SQL statements in trace file.
    93532 SQL statements in trace file.
    5 unique SQL statements in trace file.
    944521 lines in trace file.
    90 elapsed seconds in trace file.
    2. Direct SQL execution:
    TKPROF: Release 10.2.0.1.0 - Production on Wed May 16 11:03:53 2007
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Trace file: D:\oracle\product\10.2.0\admin\dae\udump\dae_ora_17004_sql2.trc
    Sort options: default
    count = number of times OCI procedure was executed
    cpu = cpu time in seconds executing
    elapsed = elapsed time in seconds executing
    disk = number of physical reads of buffers from disk
    query = number of buffers gotten for consistent read
    current = number of buffers gotten in current mode (usually for update)
    rows = number of rows processed by the fetch or execute call
    BEGIN DBMS_OUTPUT.GET_LINES(:LINES, :NUMLINES); END;
    call count cpu elapsed disk query current rows
    Parse 2 0.00 0.00 0 0 0 0
    Execute 2 0.00 0.00 0 6 0 2
    Fetch 0 0.00 0.00 0 0 0 0
    total 4 0.00 0.00 0 6 0 2
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 75
    select Category, Sub_Category, Param_Name, Param_Value
    from
    ( ( select distinct 0 as order_c,'TCH Analysis' as Category, NULL as
    Sub_Category,0 as Param_Id, 'Analyzed Sector' as Param_Name, :p_sectorid_1
    as Param_Value, 0 as SORTORDER, 0 as DISTANCE from dual)
    UNION select
    order_c,Category,Sub_Category,Param_Id,Param_Name,stragg(Param_Value) as
    Param_Value,1 as SORTORDER, 0 as DISTANCE from ( select distinct 1 as
    order_c,'TCH Analysis' as Category, NULL as Sub_Category,0 as Param_Id,
    'TCH' as Param_Name, to_char(CHANNEL) as Param_Value, 1 as SORTORDER, 0 as
    DISTANCE from sector_freq_params where SECTOR_ID=:p_SectorId_2 and
    CHAN_TYPE_ID = 2) group by order_c,Category,Sub_Category,Param_Id,
    Param_Name,SORTORDER
    UNION (select r.rr + 1 order_c, 'TCH Analysis' as
    Category, to_char(Sub_Category) as Sub_Category,
    decode(r.rr, 1, 1, 2, 3, 3,
    3, 4, 4, 5, 4) Param_Id,
    decode(r.rr, 1, 'Sector Name', 2, 'Channel
    Number', 3, 'BSIC', 4, 'Relationship', 5, 'Distance to Sector (mi)')
    Param_Name,
    decode(r.rr, 1, SECTOR_ID, 2, Channel_Number, 3, BSIC, 4,
    Relationship, 5, Distance) Param_Value, SORTORDER, DISTANCE from
    (select
    rownum Sub_Category, SECTOR_ID, SORTORDER, Channel_Number, BSIC,
    Relationship, DISTANCE
    from dae_admin.TCH_ANALYSIS_VIEW where
    SELECTED_SECTOR_ID = :p_sectorid_3 and
    SDO_WITHIN_DISTANCE(GEOLOC,
    SELECTED_GEOLOC, 'unit=MILE,distance=25')='TRUE') qry,
    (select 1 rr from
    dual union select 2 from dual union select 3 from dual union select 4 from
    dual union select 5 from dual) r)) order by SORTORDER, DISTANCE, order_c
    asc
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.04 0.03 0 1167 0 0
    Fetch 569 1.20 1.25 0 71026 2 8512
    total 571 1.25 1.29 0 72193 2 8512
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 75
    Rows Row Source Operation
    8512 SORT ORDER BY (cr=86691 pr=0 pw=0 time=1372298 us)
    8512 VIEW (cr=86691 pr=0 pw=0 time=1367047 us)
    8512 SORT UNIQUE (cr=86691 pr=0 pw=0 time=1358534 us)
    8512 UNION-ALL (cr=86691 pr=0 pw=0 time=3191633 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=2 us)
    1 SORT GROUP BY (cr=2457 pr=0 pw=0 time=16109 us)
    3 VIEW (cr=2457 pr=0 pw=0 time=15657 us)
    3 HASH UNIQUE (cr=2457 pr=0 pw=0 time=15651 us)
    3 PARTITION RANGE ALL PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3875 us)
    3 TABLE ACCESS FULL SECTOR_FREQ_PARAMS PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3869 us)
    8510 MERGE JOIN CARTESIAN (cr=84234 pr=0 pw=0 time=1166420 us)
    1702 VIEW (cr=84234 pr=0 pw=0 time=1181142 us)
    1702 COUNT (cr=8834 pr=0 pw=0 time=80783 us)
    1702 HASH JOIN (cr=8834 pr=0 pw=0 time=79089 us)
    11349 HASH JOIN (cr=6377 pr=0 pw=0 time=51629 us)
    3 PARTITION RANGE ALL PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3823 us)
    3 TABLE ACCESS FULL SECTOR_FREQ_PARAMS PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=3817 us)
    3783 NESTED LOOPS (cr=3920 pr=0 pw=0 time=28374 us)
    1 PARTITION RANGE ALL PARTITION: 1 2 (cr=4 pr=0 pw=0 time=91 us)
    1 TABLE ACCESS BY LOCAL INDEX ROWID SECTORS PARTITION: 1 2 (cr=4 pr=0 pw=0 time=78 us)
    1 INDEX RANGE SCAN SECTORS_SECTORID_IND PARTITION: 1 2 (cr=3 pr=0 pw=0 time=39 us)(object id 1834180)
    3783 PARTITION RANGE ALL PARTITION: 1 2 (cr=3916 pr=0 pw=0 time=24510 us)
    3783 TABLE ACCESS BY LOCAL INDEX ROWID SECTORS PARTITION: 1 2 (cr=3916 pr=0 pw=0 time=24504 us)
    3784 DOMAIN INDEX SECTORS_SX (cr=365 pr=0 pw=0 time=13144 us)
    478112 PARTITION RANGE ALL PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=87 us)
    478112 TABLE ACCESS FULL SECTOR_FREQ_PARAMS PARTITION: 1 2 (cr=2457 pr=0 pw=0 time=69 us)
    8510 BUFFER SORT (cr=0 pr=0 pw=0 time=2577 us)
    5 VIEW (cr=0 pr=0 pw=0 time=51 us)
    5 SORT UNIQUE (cr=0 pr=0 pw=0 time=41 us)
    5 UNION-ALL (cr=0 pr=0 pw=0 time=22 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=1 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=0 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=3 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=1 us)
    1 FAST DUAL (cr=0 pr=0 pw=0 time=1 us)
    select text
    from
    view$ where rowid=:1
    call count cpu elapsed disk query current rows
    Parse 2 0.00 0.00 0 0 0 0
    Execute 2 0.00 0.00 0 0 0 0
    Fetch 2 0.00 0.00 0 4 0 2
    total 6 0.00 0.00 0 4 0 2
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    1 TABLE ACCESS BY USER ROWID VIEW$ (cr=1 pr=0 pw=0 time=14 us)
    select u.name, o.name, a.interface_version#, o.obj#
    from
    association$ a, user$ u, obj$ o where a.obj# = :1
    and a.property = :2
    and a.statstype# = o.obj# and
    u.user# = o.owner#
    call count cpu elapsed disk query current rows
    Parse 5 0.00 0.00 0 0 0 0
    Execute 6 0.00 0.00 0 0 0 0
    Fetch 5 0.00 0.00 0 33 0 4
    total 16 0.00 0.00 0 33 0 4
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    1 NESTED LOOPS (cr=8 pr=0 pw=0 time=82 us)
    1 NESTED LOOPS (cr=6 pr=0 pw=0 time=43 us)
    1 TABLE ACCESS BY INDEX ROWID ASSOCIATION$ (cr=2 pr=0 pw=0 time=26 us)
    1 INDEX RANGE SCAN ASSOC1 (cr=1 pr=0 pw=0 time=11 us)(object id 387)
    1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=4 pr=0 pw=0 time=14 us)
    1 INDEX UNIQUE SCAN I_OBJ1 (cr=3 pr=0 pw=0 time=9 us)(object id 36)
    1 TABLE ACCESS CLUSTER USER$ (cr=2 pr=0 pw=0 time=36 us)
    1 INDEX UNIQUE SCAN I_USER# (cr=1 pr=0 pw=0 time=3 us)(object id 11)
    declare
    cost sys.ODCICost := sys.ODCICost(NULL, NULL, NULL, NULL);
    obj0 "MDSYS"."SDO_GEOMETRY" := "MDSYS"."SDO_GEOMETRY"(NULL, NULL, NULL, NULL, NULL);
    obj1 "MDSYS"."SDO_GEOMETRY" := "MDSYS"."SDO_GEOMETRY"(NULL, NULL, NULL, NULL, NULL);
    begin
    :1 := "MDSYS"."SDO_STATISTICS".ODCIStatsFunctionCost(
    sys.ODCIFuncInfo('MDSYS',
    'SDO_3GL',
    'WITHIN_DISTANCE',
    2),
    cost,
    sys.ODCIARGDESCLIST(sys.ODCIARGDESC(2, 'SECTORS', 'DAE_ADMIN', '"GEOLOC"', NULL, NULL, NULL), sys.ODCIARGDESC(2, 'SECTORS', 'DAE_ADMIN', '"GEOLOC"', NULL, NULL, NULL), sys.ODCIARGDESC(3, NULL, NULL, NULL, NULL, NULL, NULL))
    , obj0, obj1, :5,
    sys.ODCIENV(:6,:7,:8,:9));
    if cost.CPUCost IS NULL then
    :2 := -1.0;
    else
    :2 := cost.CPUCost;
    end if;
    if cost.IOCost IS NULL then
    :3 := -1.0;
    else
    :3 := cost.IOCost;
    end if;
    if cost.NetworkCost IS NULL then
    :4 := -1.0;
    else
    :4 := cost.NetworkCost;
    end if;
    exception
    when others then
    raise;
    end;
    call count cpu elapsed disk query current rows
    Parse 2 0.00 0.00 0 0 0 0
    Execute 2 0.00 0.00 0 0 0 2
    Fetch 0 0.00 0.00 0 0 0 0
    total 4 0.00 0.00 0 0 0 2
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 75 (recursive depth: 1)
    declare
    sel number;
    obj0 "MDSYS"."SDO_GEOMETRY" := "MDSYS"."SDO_GEOMETRY"(NULL, NULL, NULL, NULL, NULL);
    obj1 "MDSYS"."SDO_GEOMETRY" := "MDSYS"."SDO_GEOMETRY"(NULL, NULL, NULL, NULL, NULL);
    begin
    :1 := "MDSYS"."SDO_STATISTICS".ODCIStatsSelectivity(
    sys.ODCIPREDINFO('MDSYS',
    'SDO_3GL',
    'WITHIN_DISTANCE',
    173),
    sel,
    sys.ODCIARGDESCLIST(sys.ODCIARGDESC(3, NULL, NULL, NULL, NULL, NULL, NULL), sys.ODCIARGDESC(3, NULL, NULL, NULL, NULL, NULL, NULL), sys.ODCIARGDESC(2, 'SECTORS', 'DAE_ADMIN', '"GEOLOC"', NULL, NULL, NULL), sys.ODCIARGDESC(2, 'SECTORS', 'DAE_ADMIN', '"GEOLOC"', NULL, NULL, NULL), sys.ODCIARGDESC(3, NULL, NULL, NULL, NULL, NULL, NULL)),
    :3,
    :4
    , obj0, obj1, :5,
    sys.ODCIENV(:6,:7,:8,:9));
    if sel IS NULL then
    :2 := -1.0;
    else
    :2 := sel;
    end if;
    exception
    when others then
    raise;
    end;
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 1
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.00 0.00 0 0 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 75 (recursive depth: 1)
    select a.default_cpu_cost, a.default_io_cost
    from
    association$ a where a.obj# = :1
    and a.property = :2
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.00 0.00 0 1 0 0
    total 3 0.00 0.00 0 1 0 0
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: SYS (recursive depth: 1)
    Rows Row Source Operation
    0 TABLE ACCESS BY INDEX ROWID ASSOCIATION$ (cr=1 pr=0 pw=0 time=7 us)
    0 INDEX RANGE SCAN ASSOC1 (cr=1 pr=0 pw=0 time=6 us)(object id 387)
    declare
    cost sys.ODCICost := sys.ODCICost(NULL, NULL, NULL, NULL);
    obj1 "MDSYS"."SDO_GEOMETRY" := "MDSYS"."SDO_GEOMETRY"(NULL, NULL, NULL, NULL, NULL);
    obj2 "MDSYS"."SDO_GEOMETRY" := "MDSYS"."SDO_GEOMETRY"(NULL, NULL, NULL, NULL, NULL);
    begin
    :1 := "MDSYS"."SDO_STATISTICS".ODCIStatsIndexCost(
    sys.ODCIINDEXINFO('DAE_ADMIN',
    'SECTORS_SX',
    sys.ODCICOLINFOLIST(sys.ODCICOLINFO('DAE_ADMIN', 'SECTORS', '"GEOLOC"', 'SDO_GEOMETRY', 'MDSYS', NULL)),
    NULL,
    3,
    0),
    1.00000000,
    cost,
    sys.ODCIQUERYINFO(2,
    NULL),
    sys.ODCIPREDINFO('MDSYS',
    'SDO_WITHIN_DISTANCE',
    NULL,
    141),
    sys.ODCIARGDESCLIST(sys.ODCIARGDESC(3, NULL, NULL, NULL, NULL, NULL, NULL), sys.ODCIARGDESC(3, NULL, NULL, NULL, NULL, NULL, NULL), sys.ODCIARGDESC(2, 'SECTORS', 'DAE_ADMIN', '"GEOLOC"', NULL, NULL, NULL), sys.ODCIARGDESC(2, 'SECTORS', 'DAE_ADMIN', '"GEOLOC"', NULL, NULL, NULL), sys.ODCIARGDESC(3, NULL, NULL, NULL, NULL, NULL, NULL)),
    :6,
    :7
    , obj2, :8,
    sys.ODCIENV(:9,:10,:11,:12));
    if cost.CPUCost IS NULL then
    :2 := -1.0;
    else
    :2 := cost.CPUCost;
    end if;
    if cost.IOCost IS NULL then
    :3 := -1.0;
    else
    :3 := cost.IOCost;
    end if;
    if cost.NetworkCost IS NULL then
    :4 := -1.0;
    else
    :4 := cost.NetworkCost;
    end if;
    :5 := cost.IndexCostInfo;
    exception
    when others then
    raise;
    end;
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.00 0.00 0 0 0 0
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 75 (recursive depth: 1)
    SELECT diminfo, nvl(srid,-1)
    FROM
    ALL_SDO_GEOM_METADATA WHERE OWNER = 'DAE_ADMIN' AND TABLE_NAME =
    NLS_UPPER('SECTORS') AND '"'||COLUMN_NAME||'"' = '"GEOLOC"'
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.00 0.00 0 44 0 1
    total 3 0.00 0.00 0 44 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    Rows Row Source Operation
    1 TABLE ACCESS BY INDEX ROWID SDO_GEOM_METADATA_TABLE (cr=44 pr=0 pw=0 time=1743 us)
    1 INDEX RANGE SCAN SDO_GEOM_IDX (cr=43 pr=0 pw=0 time=1732 us)(object id 45847)
    1 UNION-ALL (cr=42 pr=0 pw=0 time=1702 us)
    1 FILTER (cr=42 pr=0 pw=0 time=1697 us)
    1 HASH JOIN (cr=42 pr=0 pw=0 time=1694 us)
    1 MERGE JOIN CARTESIAN (cr=42 pr=0 pw=0 time=955 us)
    1 NESTED LOOPS (cr=42 pr=0 pw=0 time=462 us)
    1 NESTED LOOPS OUTER (cr=38 pr=0 pw=0 time=446 us)
    1 HASH JOIN OUTER (cr=35 pr=0 pw=0 time=434 us)
    1 NESTED LOOPS OUTER (cr=17 pr=0 pw=0 time=111 us)
    1 NESTED LOOPS OUTER (cr=17 pr=0 pw=0 time=107 us)
    1 NESTED LOOPS (cr=17 pr=0 pw=0 time=100 us)
    3 NESTED LOOPS (cr=9 pr=0 pw=0 time=61 us)
    1 TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=16 us)
    1 INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=6 us)(object id 44)
    3 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=7 pr=0 pw=0 time=44 us)
    3 INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=16 us)(object id 37)
    1 TABLE ACCESS CLUSTER TAB$ (cr=8 pr=0 pw=0 time=36 us)
    1 INDEX UNIQUE SCAN I_OBJ# (cr=5 pr=0 pw=0 time=18 us)(object id 3)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=3 us)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=2 us)(object id 36)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=1 us)(object id 36)
    75 TABLE ACCESS FULL USER$ (cr=18 pr=0 pw=0 time=35 us)
    0 TABLE ACCESS CLUSTER SEG$ (cr=3 pr=0 pw=0 time=10 us)
    0 INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=3 pr=0 pw=0 time=9 us)(object id 9)
    1 TABLE ACCESS CLUSTER TS$ (cr=4 pr=0 pw=0 time=13 us)
    1 INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=6 us)(object id 7)
    1 BUFFER SORT (cr=0 pr=0 pw=0 time=489 us)
    1 FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=470 us)
    1120 FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=1125 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KZSPR (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 MERGE JOIN CARTESIAN (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us)(object id 44)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ2 (cr=0 pr=0 pw=0 time=0 us)(object id 37)
    0 TABLE ACCESS CLUSTER TAB$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_OBJ# (cr=0 pr=0 pw=0 time=0 us)(object id 3)
    0 TABLE ACCESS CLUSTER COL$ (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID COLTYPE$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_COLTYPE2 (cr=0 pr=0 pw=0 time=0 us)(object id 170)
    0 TABLE ACCESS CLUSTER TS$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_TS# (cr=0 pr=0 pw=0 time=0 us)(object id 7)
    0 TABLE ACCESS CLUSTER SEG$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=0 pr=0 pw=0 time=0 us)(object id 9)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ3 (cr=0 pr=0 pw=0 time=0 us)(object id 38)
    0 TABLE ACCESS CLUSTER USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER# (cr=0 pr=0 pw=0 time=0 us)(object id 11)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=0 us)(object id 36)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=0 us)(object id 36)
    0 TABLE ACCESS CLUSTER USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER# (cr=0 pr=0 pw=0 time=0 us)(object id 11)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=0 us)(object id 36)
    0 TABLE ACCESS CLUSTER USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER# (cr=0 pr=0 pw=0 time=0 us)(object id 11)
    0 BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KSPPI (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KSPPCV (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KZSPR (cr=0 pr=0 pw=0 time=0 us)
    0 VIEW ALL_SYNONYMS (cr=0 pr=0 pw=0 time=0 us)
    0 SORT UNIQUE (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us)(object id 44)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ2 (cr=0 pr=0 pw=0 time=0 us)(object id 37)
    0 TABLE ACCESS BY INDEX ROWID SYN$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_SYN1 (cr=0 pr=0 pw=0 time=0 us)(object id 101)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us)(object id 44)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ2 (cr=0 pr=0 pw=0 time=0 us)(object id 37)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KZSPR (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us)(object id 44)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ2 (cr=0 pr=0 pw=0 time=0 us)(object id 37)
    0 VIEW ALLSYNONYMS_TREE (cr=0 pr=0 pw=0 time=0 us)
    0 CONNECT BY WITH FILTERING (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 COUNT (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL SYN$ (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=0 us)(object id 36)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID SYN$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_SYN1 (cr=0 pr=0 pw=0 time=0 us)(object id 101)
    0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us)(object id 44)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ2 (cr=0 pr=0 pw=0 time=0 us)(object id 37)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 CONNECT BY PUMP (cr=0 pr=0 pw=0 time=0 us)
    0 COUNT (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL SYN$ (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=0 us)(object id 36)
    0 COUNT (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL SYN$ (cr=0 pr=0 pw=0 time=0 us)
    0 HASH JOIN (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS FULL OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_OBJ1 (cr=0 pr=0 pw=0 time=0 us)(object id 36)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID SYN$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_SYN1 (cr=0 pr=0 pw=0 time=0 us)(object id 101)
    0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us)(object id 44)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ2 (cr=0 pr=0 pw=0 time=0 us)(object id 37)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID SYN$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_SYN1 (cr=0 pr=0 pw=0 time=0 us)(object id 101)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID USER$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN I_USER1 (cr=0 pr=0 pw=0 time=0 us)(object id 44)
    0 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJ2 (cr=0 pr=0 pw=0 time=0 us)(object id 37)
    0 INDEX UNIQUE SCAN I_TYPED_VIEW1 (cr=0 pr=0 pw=0 time=0 us)(object id 100)
    0 INDEX UNIQUE SCAN I_VIEW1 (cr=0 pr=0 pw=0 time=0 us)(object id 99)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KZSPR (cr=0 pr=0 pw=0 time=0 us)
    SELECT nvl(sdo_level,0), nvl(sdo_numtiles,0), nvl(sdo_maxlevel, 0),
    nvl(sdo_index_table, 'DEFAULT'), sdo_index_primary, sdo_index_type,
    nvl(sdo_rtree_height, 0), nvl(sdo_rtree_num_nodes, 0),
    nvl(sdo_rtree_dimensionality, 0), nvl(sdo_rtree_fanout, 0),
    nvl(sdo_rtree_root, 'EMPTY'), nvl(sdo_rtree_seq_name, 'DEFAULT'),
    sdo_index_partition, nvl(sdo_partitioned, 0), nvl(sdo_layer_gtype,
    'DEFAULT'), nvl(sdo_index_dims, 0), nvl(sdo_rtree_pctfree, 10),
    nvl(sdo_rtree_quality, 1), nvl(sdo_index_version, 0), nvl(sdo_tablespace,
    'DEFAULT'), nvl(sdo_index_geodetic, 'FALSE'), sdo_index_status,
    nvl(sdo_nl_index_table, 'NULL'), nvl(sdo_dml_batch_size, 1),
    nvl(sdo_rtree_ent_xpnd, 0.0)
    FROM
    all_sdo_index_metadata WHERE sdo_index_owner = 'DAE_ADMIN' and
    sdo_index_name = 'SECTORS_SX' and sdo_index_partition = UPPER(:ptname)
    ORDER BY SDO_INDEX_PRIMARY
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.00 0.00 0 43 0 1
    total 3 0.00 0.00 0 43 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    select count(*)
    from
    mdsys.geodetic_srids where srid = 99900001
    call count cpu elapsed disk query current rows
    Parse 3405 0.01 0.01 0 0 0 0
    Execute 3405 0.04 0.03 0 0 0 0
    Fetch 3405 0.07 0.03 0 10215 0 3405
    total 10215 0.14 0.08 0 10215 0 3405
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    Rows Row Source Operation
    1 SORT AGGREGATE (cr=3 pr=0 pw=0 time=26 us)
    0 TABLE ACCESS BY INDEX ROWID SDO_CS_SRS (cr=3 pr=0 pw=0 time=17 us)
    1 INDEX UNIQUE SCAN SYS_C003941 (cr=2 pr=0 pw=0 time=9 us)(object id 48833)
    select wktext, srid
    from
    mdsys.cs_srs where srid = 99900001
    call count cpu elapsed disk query current rows
    Parse 1704 0.00 0.01 0 0 0 0
    Execute 1704 0.00 0.01 0 0 0 0
    Fetch 1704 0.03 0.01 0 5112 0 1704
    total 5112 0.03 0.03 0 5112 0 1704
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    Rows Row Source Operation
    1 TABLE ACCESS BY INDEX ROWID SDO_CS_SRS (cr=3 pr=0 pw=0 time=8 us)
    1 INDEX UNIQUE SCAN SYS_C003941 (cr=2 pr=0 pw=0 time=5 us)(object id 48833)
    SELECT partition_count
    FROM
    all_part_indexes WHERE owner='DAE_ADMIN' and index_name='SECTORS_SX'
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.00 0.00 0 18 0 1
    total 3 0.00 0.00 0 18 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    Rows Row Source Operation
    1 FILTER (cr=18 pr=0 pw=0 time=70 us)
    1 NESTED LOOPS (cr=18 pr=0 pw=0 time=67 us)
    1 NESTED LOOPS OUTER (cr=15 pr=0 pw=0 time=59 us)
    1 NESTED LOOPS (cr=13 pr=0 pw=0 time=52 us)
    1 NESTED LOOPS (cr=10 pr=0 pw=0 time=42 us)
    1 NESTED LOOPS (cr=7 pr=0 pw=0 time=29 us)
    1 TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=8 us)
    1 INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=4 us)(object id 44)
    1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=5 pr=0 pw=0 time=20 us)
    1 INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=14 us)(object id 37)
    1 TABLE ACCESS BY INDEX ROWID PARTOBJ$ (cr=3 pr=0 pw=0 time=10 us)
    1 INDEX UNIQUE SCAN I_PARTOBJ$ (cr=2 pr=0 pw=0 time=6 us)(object id 263)
    1 TABLE ACCESS BY INDEX ROWID IND$ (cr=3 pr=0 pw=0 time=8 us)
    1 INDEX UNIQUE SCAN I_IND1 (cr=2 pr=0 pw=0 time=5 us)(object id 39)
    0 TABLE ACCESS CLUSTER TS$ (cr=2 pr=0 pw=0 time=6 us)
    0 INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=4 us)(object id 7)
    1 INDEX UNIQUE SCAN I_OBJ1 (cr=3 pr=0 pw=0 time=7 us)(object id 36)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KZSPR (cr=0 pr=0 pw=0 time=0 us)
    SELECT nvl(sdo_index_partition, 'DEFAULT'), nvl(sdo_index_table, 'DEFAULT'),
    nvl(sdo_rtree_height,0), nvl(sdo_rtree_num_nodes,0),
    nvl(sdo_rtree_root,'EMPTY'), nvl(sdo_layer_gtype, 'DEFAULT'),
    nvl(sdo_index_status, 'VALID'), sdo_root_mbr
    FROM
    all_sdo_index_metadata WHERE sdo_index_owner='DAE_ADMIN' and sdo_index_name=
    'SECTORS_SX' and sdo_index_partition is not null ORDER BY
    sdo_index_partition
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 2 0.00 0.00 0 45 0 2
    total 4 0.00 0.00 0 45 0 2
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    Rows Row Source Operation
    2 TABLE ACCESS BY INDEX ROWID SDO_INDEX_METADATA_TABLE (cr=45 pr=0 pw=0 time=155 us)
    2 INDEX RANGE SCAN SDO_IDX_MDATA_IDX (cr=43 pr=0 pw=0 time=142 us)(object id 48798)
    1 FILTER (cr=40 pr=0 pw=0 time=121 us)
    1 NESTED LOOPS OUTER (cr=40 pr=0 pw=0 time=118 us)
    1 NESTED LOOPS OUTER (cr=38 pr=0 pw=0 time=111 us)
    1 NESTED LOOPS OUTER (cr=34 pr=0 pw=0 time=100 us)
    1 NESTED LOOPS (cr=31 pr=0 pw=0 time=92 us)
    1 NESTED LOOPS (cr=22 pr=0 pw=0 time=78 us)
    1 NESTED LOOPS OUTER (cr=18 pr=0 pw=0 time=66 us)
    1 NESTED LOOPS (cr=15 pr=0 pw=0 time=56 us)
    3 NESTED LOOPS (cr=9 pr=0 pw=0 time=34 us)
    1 TABLE ACCESS BY INDEX ROWID USER$ (cr=2 pr=0 pw=0 time=6 us)
    1 INDEX UNIQUE SCAN I_USER1 (cr=1 pr=0 pw=0 time=4 us)(object id 44)
    3 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=7 pr=0 pw=0 time=24 us)
    3 INDEX RANGE SCAN I_OBJ2 (cr=4 pr=0 pw=0 time=9 us)(object id 37)
    1 TABLE ACCESS BY INDEX ROWID IND$ (cr=6 pr=0 pw=0 time=20 us)
    1 INDEX UNIQUE SCAN I_IND1 (cr=5 pr=0 pw=0 time=12 us)(object id 39)
    1 TABLE ACCESS CLUSTER TS$ (cr=3 pr=0 pw=0 time=9 us)
    1 INDEX UNIQUE SCAN I_TS# (cr=2 pr=0 pw=0 time=4 us)(object id 7)
    1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=4 pr=0 pw=0 time=10 us)
    1 INDEX UNIQUE SCAN I_OBJ1 (cr=3 pr=0 pw=0 time=6 us)(object id 36)
    1 TABLE ACCESS CLUSTER USER$ (cr=9 pr=0 pw=0 time=13 us)
    1 INDEX UNIQUE SCAN I_USER# (cr=1 pr=0 pw=0 time=3 us)(object id 11)
    0 TABLE ACCESS CLUSTER SEG$ (cr=3 pr=0 pw=0 time=7 us)
    0 INDEX UNIQUE SCAN I_FILE#_BLOCK# (cr=3 pr=0 pw=0 time=6 us)(object id 9)
    1 TABLE ACCESS BY INDEX ROWID OBJ$ (cr=4 pr=0 pw=0 time=7 us)
    1 INDEX UNIQUE SCAN I_OBJ1 (cr=3 pr=0 pw=0 time=4 us)(object id 36)
    1 TABLE ACCESS CLUSTER USER$ (cr=2 pr=0 pw=0 time=6 us)
    1 INDEX UNIQUE SCAN I_USER# (cr=1 pr=0 pw=0 time=2 us)(object id 11)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN I_OBJAUTH1 (cr=0 pr=0 pw=0 time=0 us)(object id 103)
    0 FIXED TABLE FULL X$KZSRO (cr=0 pr=0 pw=0 time=0 us)
    0 FIXED TABLE FULL X$KZSPR (cr=0 pr=0 pw=0 time=0 us)
    SELECT info
    from
    DAE_ADMIN.MDRT_1BFCC9$ where rowid = :rid
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 0.00 0.00 0 1 0 1
    total 3 0.00 0.00 0 1 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    Rows Row Source Operation
    1 TABLE ACCESS BY USER ROWID MDRT_1BFCC9$ (cr=1 pr=0 pw=0 time=14 us)
    SELECT info
    from
    DAE_ADMIN.MDRT_1C72A2$ where rowid = :rid
    call count cpu elapsed disk query current rows
    Parse 2 0.00 0.00 0 0 0 0
    Execute 187 0.00 0.00 0 0 0 0
    Fetch 187 0.01 0.00 0 187 0 187
    total 376 0.01 0.00 0 187 0 187
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62 (recursive depth: 1)
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 3 0.00 0.00 0 0 0 0
    Execute 3 0.04 0.03 0 1173 0 2
    Fetch 569 1.20 1.25 0 71026 2 8512
    total 575 1.25 1.29 0 72199 2 8514
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 5128 0.01 0.03 0 0 0 0
    Execute 5314 0.04 0.05 0 0 0 3
    Fetch 5310 0.12 0.04 0 15703 0 5308
    total 15752 0.18 0.12 0 15703 0 5311
    Misses in library cache during parse: 0
    5123 user SQL statements in session.
    8 internal SQL statements in session.
    5131 SQL statements in session.
    Trace file: D:\oracle\product\10.2.0\admin\dae\udump\dae_ora_17004_sql2.trc
    Trace file compatibility: 10.01.00
    Sort options: default
    0 session in tracefile.
    5123 user SQL statements in trace file.
    8 internal SQL statements in trace file.
    5131 SQL statements in trace file.
    16 unique SQL statements in trace file.
    50973 lines in trace file.
    21 elapsed seconds in trace file.

  • Odd error while opening a ref cursor

    Hi.
    I have a procedure in a package that has both in and out parameters. One of those out parameters is a ref cursor. The procedure creates a dynamic query and then executes it, then it opens the cursor:
    PROCEDURE PROC(
    A IN VARCHAR2,
    B IN VARCHAR2,
    C OUT TYPES.cursorType; --(TYPES is a package whose only use is to declare a cursor type)
    ) IS
    --DECLARATIONS
    OPEN C FOR 'SELECT A, B, C, D...';
    END;
    When I execute the package in an anonymous block it throws the error:
    ORA-00938: not enough arguments for function, just in the line where the cursor is being opened.
    Any ideas?

    is everything defined correctly?
    create or replace package types  as
      type cursorType is ref cursor;
    end types;
    SQL> set serveroutput on
    SQL> declare
      2 
      3    ref_C types.cursorType;
      4   
      5    v_a varchar2(1);
      6    v_b varchar2(1);
      7    v_c varchar2(1);
      8    v_d varchar2(1);
      9   
    10    procedure Proc (a in varchar2
    11                   ,b in varchar2
    12                   ,C out types.cursorType) as
    13 
    14      begin
    15        open C for 'select :1, :2, ''c'', ''d'' from dual' using a, b;
    16    end  Proc;
    17  begin
    18 
    19 
    20    Proc('a', 'b', ref_C);
    21   
    22    fetch ref_C into v_a, v_b, v_c, v_d;
    23    if (ref_C%found) then
    24      dbms_output.put_line(v_a);
    25      dbms_output.put_line(v_b);
    26      dbms_output.put_line(v_c);
    27      dbms_output.put_line(v_d);
    28    end if;
    29   
    30   
    31  end;
    32  /
    a
    b
    c
    dP;
    Edited by: bluefrog on Feb 18, 2010 6:07 PM

  • Problem in opening a ref cursor.

    Hi,
    I'm getting the following error when i'm trying to open the ref cursor. PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    What i'm trying to do is I'm dumping the data into pl/sql table and i want retrieving the by using a ref cursor. Please see the code and help me out.
    CREATE OR REPLACE PACKAGE CPS_RECR.pg_pool_status AS
      TYPE pool_rec IS RECORD (
       status  varchar2(50)
      ,stsno number
      ,stscode varchar2(5)
      ,candidatename varchar2(200)
      ,monyear varchar2(10)
      ,yyyymm number
      ,stscnt number
      --type rec_sts_tab is table of number ;--index by pls_integer;
      type pool_tab IS table of pool_rec index by binary_integer;
      type pool_cv is REF CURSOR return pool_rec;
    FUNCTION pool_status_query(p_start_date in date,p_end_date in  date,p_invitedtopoolbit  in number,p_showedForPoolBit in  number)
       RETURN pool_tab;--pool_cv ;
      cursor cur_pool(p_start_date date,p_end_date date,p_invitedtopoolbit number,p_showedForPoolBit number)
      is
         SELECT   distinct to_char(date1,'yyyymm')yearmonth
                  FROM acs100data a,
                     acs100_candidate_verification b,                
                     acs100_candidate_pool d
                 WHERE UPPER (a.basic_email) = UPPER (b.email)
                 AND (b.candidate_status IN ('FORL', 'FWRT') or BITAND (b.candidate_status_bit, 4 ) > 0
                  or BITAND (b.candidate_status_bit, 2) > 0)                         
                 AND d.pool_id = b.pool_id
                 AND pool_date BETWEEN p_start_date AND p_end_date
                 AND is_tentative_date IS NULL  ;
      cursor cur_name(p_yyyymm varchar2,p_cond number,p_start_date date,p_end_date date)
      is
      select *
      from (select distinct (case
                                when p_cond = 0 and b.candidate_status = 'FORL'
                                   then (last_name || first_name)
                                when p_cond = 1 and b.candidate_status = 'FWRT'
                                   then (last_name || first_name)
                                when p_cond = 2
                                and bitand (b.candidate_status_bit, p_cond) > 0
                                   then (last_name || first_name)
                                when p_cond = 4
                                and bitand (b.candidate_status_bit, p_cond) > 0
                                   then (last_name || first_name)
                             end
                            ) candidatename
                       from acs100data a,
                            acs100_candidate_verification b,
                            acs100_candidate_pool d
                      where upper (a.basic_email) = upper (b.email)
                        and d.pool_id = b.pool_id
                        and pool_date between p_start_date and p_end_date
                        and to_char (date1, 'yyyymm') = p_yyyymm
                        and is_tentative_date is null)
    where candidatename is not null;  
    END pg_pool_status;
    CREATE OR REPLACE PACKAGE BODY CPS_RECR.pg_pool_status
    AS
       FUNCTION pool_status_query (
          p_start_date         IN   DATE,
          p_end_date           IN   DATE,
          p_invitedtopoolbit   IN   NUMBER,
          p_showedforpoolbit   IN   NUMBER
          RETURN pool_tab--pool_cv
       IS
          tab_pool    pool_tab;
          temp_rf    pool_cv;
          n_index     NUMBER         := 1;
          --rec_sts_data  rec_sts_tab;
          n_stscnt    NUMBER;
          vc_status   VARCHAR2 (100);
          vc_label  varchar2(1000);
          vc_name  varchar2(100);
       BEGIN
          tab_pool.DELETE;
          vc_label :='Opening Pool cursor';
          FOR rec_pool IN cur_pool (p_start_date,
                                    p_end_date,
                                    p_invitedtopoolbit,
                                    p_showedforpoolbit
          LOOP
              if cur_pool%notfound then
                exit;
              end if;
             vc_label :='Opening p_cond cursor';
             FOR p_cond IN 0 .. 3
             LOOP
                n_stscnt := 0;
                vc_status := NULL;
                begin
                    SELECT   SUM
                                (NVL
                                    (COUNT
                                        (CASE
                                            WHEN p_cond = 0
                                            AND b.candidate_status = 'FORL'
                                               THEN (last_name || first_name)
                                            WHEN p_cond = 1
                                            AND b.candidate_status = 'FWRT'
                                               THEN (last_name || first_name)
                                            WHEN p_cond = 2
                                            AND BITAND (b.candidate_status_bit,
                                                        p_cond) > 0
                                               THEN (last_name || first_name)
                                            WHEN p_cond = 4
                                            AND BITAND (b.candidate_status_bit,
                                                        p_cond) > 0
                                               THEN (last_name || first_name)
                                         END
                                     0
                                ) cnt,
                             DECODE (p_cond,
                                     0, 'FAILED WRITTEN TEST',
                                     1, 'FAILED **** TEST',
                                     2, 'Invited for Pool',
                                     4, 'Showed up for Pool'
                                    ) status
                        INTO n_stscnt,
                             vc_status
                        FROM acs100data a,
                             acs100_candidate_verification b,
                             acs100_candidate_pool d
                       WHERE UPPER (a.basic_email) = UPPER (b.email)
                         AND d.pool_id = b.pool_id
                         AND pool_date BETWEEN p_start_date AND p_end_date
                         AND TO_CHAR (date1, 'yyyymm') = rec_pool.yearmonth
                         AND is_tentative_date IS NULL
                    GROUP BY candidate_status,
                             b.candidate_status_bit,
                             DECODE (p_cond,
                                     0, 'FAILED WRITTEN TEST',
                                     1, 'FAILED **** TEST',
                                     2, 'Invited for Pool',
                                     4, 'Showed up for Pool'
                  exception
                     when no_data_found
                     then
                        n_stscnt :=0;
                        vc_status :=null;
                 end;
                vc_label :='Opening name cursor';         
                FOR rec_name IN cur_name (rec_pool.yearmonth,
                                          p_cond,
                                          p_start_date,
                                          p_end_date
                LOOP
                   if cur_name%notfound then
                   exit;
                   end if;
                   tab_pool (n_index).yyyymm := rec_pool.yearmonth;
                   tab_pool (n_index).stscnt := n_stscnt;
                   tab_pool (n_index).status := vc_status;
                   tab_pool (n_index).candidatename := rec_name.candidatename;
                   dbms_output.put_line('tab_pool(n_index).yyyymm  : '||tab_pool(n_index).yyyymm);
                   dbms_output.put_line('tab_pool(n_index).stscnt : '||tab_pool(n_index).stscnt);
                   dbms_output.put_line('tab_pool(n_index).status : '||tab_pool(n_index).status);
                   dbms_output.put_line('tab_pool(n_index).candidatename : '||tab_pool(n_index).candidatename);
                   vc_name :=rec_name.candidatename;
                END LOOP;
                n_index := n_index + 1;
             END LOOP;
          END LOOP;      
          RETURN tab_pool;
       exception
         when others
         then
             dbms_output.put_line('error :'||vc_label||'--'||  vc_name); 
       END;
    END pg_pool_status;
    ---run script
    DECLARE
      RetVal CPS_RECR.PG_POOL_STATUS.pool_tab;
      P_START_DATE DATE;
      P_END_DATE DATE;
      P_INVITEDTOPOOLBIT NUMBER;
      P_SHOWEDFORPOOLBIT NUMBER;
    temp_cv CPS_RECR.PG_POOL_STATUS.pool_cv;
    BEGIN
      P_START_DATE := to_date('09/01/2008','mm/dd/yyyy');
      P_END_DATE := to_date('09/30/2008','mm/dd/yyyy');
      P_INVITEDTOPOOLBIT := 2;
      P_SHOWEDFORPOOLBIT := 4;
      open temp_cv for select * from  table((CPS_RECR.PG_POOL_STATUS.POOL_STATUS_QUERY ( P_START_DATE, P_END_DATE, P_INVITEDTOPOOLBIT, P_SHOWEDFORPOOLBIT )) );
      end loop;
    exception
       when others
       then
          dbms_output.put_line(sqlerrm);
    END;

    Satyaki,
    It doesn't help me out. I'm worndering one of code sample is working fine. i didn't my current is giving the problem.
    FYI, please see the some code i followed.
    SQL> Create or replace PACKAGE cv IS
      2     type comp_rec is RECORD
      3               (deptno number,
      4                ename  varchar(10),
      5                compensation number);
      6     type comp_tbl IS table of comp_rec;
      7     function get_coll return comp_tbl pipelined;
      8     temp_tbl comp_tbl := comp_tbl();
      9     type comp_cv is REF CURSOR return comp_rec;
    10  end;
    11  /
    Package created.
    SQL> Create or replace PACKAGE body cv IS
      2     function get_coll return comp_tbl pipelined
      3     is
      4     begin
      5      for i in 1..temp_tbl.count loop
      6       pipe row(temp_tbl(i));
      7      end loop;
      8      return;
      9     end;
    10  end;
    11  /
    Package body created.
    SQL> declare
      2     temp_cv cv.comp_cv;
      3     rc cv.comp_rec;
      4  begin
      5           cv.temp_tbl.delete;
      6           cv.temp_tbl.extend;
      7    cv.temp_tbl(1).deptno:=10;
      8    cv.temp_tbl(1).ename:='1223';
      9    cv.temp_tbl(1).compensation:=10;
    10  
    11          -- erroring out
    12   open temp_cv for select * from  table(cv.get_coll);
    13          fetch temp_cv into rc;
    14          dbms_output.put_line('Deptno is ' || rc.deptno);
    15          dbms_output.put_line('ename is ' || rc.ename);
    16  end;
    17  /
    Deptno is 10
    ename is 1223
    PL/SQL procedure successfully completed.

  • Is there a different way to open a cursor for a ref cursor procedure?

    hello everybody
    i have two cursors, cur_a and cur_b, declared somewhere else in my application.
    These two cursors have the same fields, in the same order, and i have to treat both in the same way. So i wrote a routine that gets as input a ref cursor based on the cur_a rowtype, and i am trying to use this routine for both.
    The problem is that i am not able to open outside the routine the cursor in a different way than usual...
    the common method is :
    declare curs ref cursor ...
    begin
    open curs for (select *...)
    end;
    instead i would like to obtain something different
    declare curs ref cursor ...
    begin
    open curs for cur_a
    end;

    hi
    thanks for answering
    i wanted just to give a better idea, anyway you were near to get it.
    the only difference is that the two cursors are not written in dynamic sql, just like strings, but are real cursors.
    anyway, this is the version of the package i need, but i am not able to compile
    (your original code is commented and immediately below there is my code)
    CREATE OR REPLACE PACKAGE BODY mytest
    IS
    --cur_a VARCHAR2(200) := 'SELECT dummy FROM DUAL';
    CURSOR cur_a
    IS
    SELECT dummy
    FROM DUAL;
    --cur_b VARCHAR2(200) := 'SELECT ''fred'' FROM DUAL';
    CURSOR cur_b
    IS
    SELECT 'fred' fred
    FROM DUAL;
    TYPE t_cur_a IS REF CURSOR
    RETURN cur_a%ROWTYPE
    --PROCEDURE routine_a_b (p_cur SYS_REFCURSOR) IS
    PROCEDURE routine_a_b (p_cur t_cur_a)
    IS
    v_x VARCHAR2 (10);
    BEGIN
    LOOP
    FETCH p_cur
    INTO v_x;
    EXIT WHEN p_cur%NOTFOUND;
    DBMS_OUTPUT.put_line (v_x);
    END LOOP;
    END;
    PROCEDURE doit
    IS
    --v_curs SYS_REFCURSOR;
    v_curs t_cur_a;
    BEGIN
    NULL;
    -- open v_curs FOR cur_a;
    OPEN v_curs FOR cur_a;
    routine_a_b (v_curs);
    CLOSE v_curs;
    -- open v_curs FOR cur_b;
    -- routine_a_b(v_curs);
    -- close v_curs;
    END;
    END;
    the error is:
    cursor 'V_CURS' cannot be used in dynamic SQL OPEN statement
    i did read that if use weak ref cursor, it could work, so i declare the ref cursor type in this way:
    TYPE t_cur_a IS REF CURSOR;
    instead than
    TYPE t_cur_a IS REF CURSOR
    RETURN cur_a%ROWTYPE
    what i get is another error (in the open cursor command)
    PLS-00382: expression is of wrong type....
    but if i replace
    OPEN v_curs FOR cur_a;
    with
    OPEN v_curs for select dummy from dual;
    it works... but i already knew it.. :-)
    anyway, i used a work around to resolve it, so it's just philosophy

  • How do i return data, when my sql was opened in a ref cursor.

    In Pl/sql, I was been bunged in the following situation:
    I am opening a ref cursor, where i couldn't determine the return type. In that case how will i return the data for those sql.
    Sample code :
    Declare
    Type a_ref IS REF CURSOR;
    C1 a_ref;
    Begin
    Open c1 for ‘select a, b, c from D’;
    Fetch c1 into ??????;
    Close c1;
    End;
    My doubt resides in ??? part..
    The columns in the select clause will vary dynamically.
    Hence how can I declare my variable..
    Regards,
    Bala

    Well, nothing is over to change mind if possible. I think the knowledge of
    alternatives is always useful... :).
    As for DBMS_SQL, it's an alternative to ref cursors too, but surely inside PL/SQL:
    SQL> declare
      2   c integer;
      3   desc_t DBMS_SQL.DESC_TAB;
      4   col_cnt integer;
      5   type gvarray is varray(25) of varchar(40);
      6   values1 gvarray := gvarray();
      7   a integer;
      8  begin
      9   values1.extend(25);
    10   c := dbms_sql.open_cursor;
    11   DBMS_SQL.PARSE(c,'select hiredate,ename from emp' ,DBMS_SQL.NATIVE);
    12   DBMS_SQL.DESCRIBE_COLUMNS (
    13     c,
    14     col_cnt,
    15     desc_t);
    16   for j in 1..col_cnt loop
    17     dbms_sql.define_column(c,j,values1(j),40);
    18   end loop;
    19   a:=dbms_sql.execute(c);
    20   loop
    21     if dbms_sql.fetch_rows(c) > 0 then
    22      for j in 1..col_cnt loop
    23        dbms_sql.column_value(c,j,values1(j));
    24        dbms_output.put_line('Row number ' || j || ', column ' || desc_t(j).col_name || ', value
    25        || values1(j) );
    26      end loop;
    27     else
    28       exit;
    29     end if;
    30   end loop;
    31   dbms_sql.close_cursor(c);
    32  end;
    33  /
    Row number 1, column HIREDATE, value 17.12.80
    Row number 2, column ENAME, value SMITH
    Row number 1, column HIREDATE, value 20.02.81
    Row number 2, column ENAME, value ALLEN
    Row number 1, column HIREDATE, value 22.02.81
    Row number 2, column ENAME, value WARD
    Row number 1, column HIREDATE, value 02.04.81
    Row number 2, column ENAME, value JONES
    Row number 1, column HIREDATE, value 28.09.81
    Row number 2, column ENAME, value MARTIN
    Row number 1, column HIREDATE, value 01.05.81
    Row number 2, column ENAME, value BLAKE
    Row number 1, column HIREDATE, value 09.06.81
    Row number 2, column ENAME, value CLARK
    Row number 1, column HIREDATE, value 19.04.87
    Row number 2, column ENAME, value SCOTT
    Row number 1, column HIREDATE, value 17.11.81
    Row number 2, column ENAME, value KING
    Row number 1, column HIREDATE, value 08.09.81
    Row number 2, column ENAME, value TURNER
    Row number 1, column HIREDATE, value 23.05.87
    Row number 2, column ENAME, value ADAMS
    Row number 1, column HIREDATE, value 03.12.81
    Row number 2, column ENAME, value JAMES
    Row number 1, column HIREDATE, value 03.12.81
    Row number 2, column ENAME, value FORD
    Row number 1, column HIREDATE, value 23.01.82
    Row number 2, column ENAME, value MILLER
    PL/SQL procedure successfully completed.Rgds.

  • How to open a Ref cursor in Oracle Reports

    I have a stored procedure that returns a ref cursor as an output parameter. I want to call this stored procedure in Oracle Reports After Form trigger. I am having trouble with the syntax of the output parameter. Event_record is the name of the cursor.
    After Form Trigger
    pkg_DEAL_WHITESHEET_CONCERTS.prc_Event_Information(:p_field_6,event_record);
    Error: Event_record must be declared

    Re-Write the procedure as Package Spec and Body. Declare the REFCursor in the Package Spec. Probably that helps.

  • Ref Cursor and For Loop

    The query below will return values in the form of
    bu     seq     eligible
    22     2345     Y
    22     2345     N
    22     1288     N
    22     1458     Y
    22     1458     N
    22     1234     Y
    22     1333     N
    What I am trying to accomplish is to loop through the records returned.
    for each seq if there is a 'N' in the eligible column return no record for that seq
    eg seq 2345 has 'Y' and 'N' thus no record should be returned.
    seq 1234 has only a 'Y' then return the record
    seq 1333 has 'N' so return no record.
    How would I accomplish this with a ref Cursor and pass the values to the front end application.
    Procedure InvalidNOs(io_CURSOR OUT T_CURSOR)
         IS
              v_CURSOR T_CURSOR;
         BEGIN
    OPEN v_CURSOR FOR
    '     select bu, seq, eligible ' ||
    '     from (select bu, seq, po, tunit, tdollar,eligible,max(eligible) over () re ' ||
    '          from (select bu, seq, po, tunit, tdollar,eligible ' ||
    '          from ( ' ||
    '          select bu, seq, po, tunit, tdollar, eligible, sum(qty) qty, sum(price*qty) dollars ' ||
    '               from ' ||
    '               ( select /*+ use_nl(t,h,d,s) */ ' ||
    '               h.business_unit_id bu, h.edi_sequence_id seq, d.edi_det_sequ_id dseq, ' ||
    '                    s.edi_size_sequ_id sseq, h.po_number po, h.total_unit tUnit, h.total_amount tDollar, ' ||
    '                    s.quantity qty, s.unit_price price,' ||
    '               (select (case when count(*) = 0 then ''Y'' else ''N'' end) ' ||
    '          from sewn.NT_edii_po_det_error ' ||
    '          where edi_det_sequ_id = d.edi_det_sequ_id ' ||
    '               ) eligible ' ||
    '     from sewn.nt_edii_purchase_size s, sewn.nt_edii_purchase_det d, ' ||
    '     sewn.nt_edii_purchase_hdr h, sewn.nt_edii_param_temp t ' ||
    '     where h.business_unit_id = t.business_unit_id ' ||
    '     and h.edi_sequence_id = t.edi_sequence_id ' ||
    '     and h.business_unit_id = d.business_unit_id ' ||
    '     and h.edi_sequence_id = d.edi_sequence_id ' ||
    '     and d.business_unit_id = s.business_unit_id ' ||
    '     and d.edi_sequence_id = s.edi_sequence_id ' ||
    '     and d.edi_det_sequ_id = s.edi_det_sequ_id ' ||
    '     ) group by bu, seq, po, tunit, tdollar, eligible ' ||
    '     ) ' ||
    '     group by bu, seq, po, tunit, tdollar, eligible)) ';
              io_CURSOR := v_CURSOR;
    END     InvalidNOs;

    One remark why you should not use the assignment between ref cursor
    variables.
    (I remembered I saw already such thing in your code).
    Technically you can do it but it does not make sense and it can confuse your results.
    In the opposite to usual variables, when your assignment copies value
    from one variable to another, cursor variables are pointers to the memory.
    Because of this when you assign one cursor variable to another you just
    duplicate memory pointers. You don't copy result sets. What you do for
    one pointer is that you do for another and vice versa. They are the same.
    I think the below example is self-explained:
    SQL> /* usual variables */
    SQL> declare
      2   a number;
      3   b number;
      4  begin
      5   a := 1;
      6   b := a;
      7   a := a + 1;
      8   dbms_output.put_line('a = ' || a);
      9   dbms_output.put_line('b = ' || b);
    10  end;
    11  /
    a = 2
    b = 1
    PL/SQL procedure successfully completed.
    SQL> /* cursor variables */
    SQL> declare
      2   a sys_refcursor;
      3   b sys_refcursor;
      4  begin
      5   open a for select empno from emp;
      6   b := a;
      7   close b;
      8 
      9   /* next action is impossible - cursor already closed */
    10   /* a and b are the same ! */
    11   close a;
    12  end;
    13  /
    declare
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at line 11
    SQL> declare
      2   a sys_refcursor;
      3   b sys_refcursor;
      4   vempno emp.empno%type;
      5 
      6  begin
      7   open a for select empno from emp;
      8   b := a;
      9 
    10   /* Fetch first row from a */
    11   fetch a into vempno;
    12   dbms_output.put_line(vempno);
    13 
    14   /* Fetch from b gives us SECOND row, not first -
    15      a and b are the SAME */
    16 
    17   fetch b into vempno;
    18   dbms_output.put_line(vempno);
    19 
    20 
    21  end;
    22  /
    7369
    7499
    PL/SQL procedure successfully completed.Rgds.
    Message was edited by:
    dnikiforov

  • ORA-01008 with ref cursor and dynamic sql

    When I run the follwing procedure:
    variable x refcursor
    set autoprint on
    begin
      Crosstab.pivot(p_max_cols => 4,
       p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by job order by deptno) rn from scott.emp group by job, deptno',
       p_anchor => Crosstab.array('JOB'),
       p_pivot  => Crosstab.array('DEPTNO', 'CNT'),
       p_cursor => :x );
    end;I get the following error:
    ^----------------
    Statement Ignored
    set autoprint on
    begin
    adsmgr.Crosstab.pivot(p_max_cols => 4,
    p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by
    p_anchor => adsmgr.Crosstab.array('JOB'),
    p_pivot => adsmgr.Crosstab.array('DEPTNO', 'CNT'),
    p_cursor => :x );
    end;
    ORA-01008: not all variables bound
    I am running this on a stored procedure as follows:
    create or replace package Crosstab
    as
        type refcursor is ref cursor;
        type array is table of varchar2(30);
        procedure pivot( p_max_cols       in number   default null,
                         p_max_cols_query in varchar2 default null,
                         p_query          in varchar2,
                         p_anchor         in array,
                         p_pivot          in array,
                         p_cursor in out refcursor );
    end;
    create or replace package body Crosstab
    as
    procedure pivot( p_max_cols          in number   default null,
                     p_max_cols_query in varchar2 default null,
                     p_query          in varchar2,
                     p_anchor         in array,
                     p_pivot          in array,
                     p_cursor in out refcursor )
    as
        l_max_cols number;
        l_query    long;
        l_cnames   array;
    begin
        -- figure out the number of columns we must support
        -- we either KNOW this or we have a query that can tell us
        if ( p_max_cols is not null )
        then
            l_max_cols := p_max_cols;
        elsif ( p_max_cols_query is not null )
        then
            execute immediate p_max_cols_query into l_max_cols;
        else
            RAISE_APPLICATION_ERROR(-20001, 'Cannot figure out max cols');
        end if;
        -- Now, construct the query that can answer the question for us...
        -- start with the C1, C2, ... CX columns:
        l_query := 'select ';
        for i in 1 .. p_anchor.count
        loop
            l_query := l_query || p_anchor(i) || ',';
        end loop;
        -- Now add in the C{x+1}... CN columns to be pivoted:
        -- the format is "max(decode(rn,1,C{X+1},null)) cx+1_1"
        for i in 1 .. l_max_cols
        loop
            for j in 1 .. p_pivot.count
            loop
                l_query := l_query ||
                    'max(decode(rn,'||i||','||
                               p_pivot(j)||',null)) ' ||
                                p_pivot(j) || '_' || i || ',';
            end loop;
        end loop;
        -- Now just add in the original query
        l_query := rtrim(l_query,',')||' from ( '||p_query||') group by ';
        -- and then the group by columns...
        for i in 1 .. p_anchor.count
        loop
            l_query := l_query || p_anchor(i) || ',';
        end loop;
        l_query := rtrim(l_query,',');
        -- and return it
        execute immediate 'alter session set cursor_sharing=force';
        open p_cursor for l_query;
        execute immediate 'alter session set cursor_sharing=exact';
    end;
    end;
    /I can see from the error message that it is ignoring the x declaration, I assume it is because it does not recognise the type refcursor from the procedure.
    How do I get it to recognise this?
    Thank you in advance

    Thank you for your help
    This is the version of Oracle I am running, so this may have something to do with that.
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    I found this on Ask Tom (http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3027089372477)
    Hello, Tom.
    I have one bind variable in a dynamic SQL expression.
    When I open cursor for this sql, it gets me to ora-01008.
    Please consider:
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
    JServer Release 8.1.7.4.1 - Production
    SQL> declare
      2    type cur is ref cursor;
      3    res cur;
      4  begin
      5    open res for
      6    'select * from (select * from dual where :p = 1) connect by 1 = 1'
      7    using 1;
      8  end;
      9  /
    declare
    ERROR at line 1:
    ORA-01008: not all variables bound
    ORA-06512: at line 5
    SQL> declare
      2    type cur is ref cursor;
      3    res cur;
      4  begin
      5    open res for
      6    'select * from (select * from dual where :p = 1) connect by 1 = 1'
      7    using 1, 2;
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    And if I run the same thing on 10g -- all goes conversely. The first part runs ok, and the second
    part reports "ORA-01006: bind variable does not exist" (as it should be, I think). Remember, there
    is ONE bind variable in sql, not two. Is it a bug in 8i?
    What should we do to avoid this error running the same plsql program code on different Oracle
    versions?
    P.S. Thank you for your invaluable work on this site.
    Followup   June 9, 2005 - 6pm US/Eastern:
    what is the purpose of this query really?
    but it would appear to be a bug in 8i (since it should need but one).  You will have to work that
    via support. I changed the type to tarray to see if the reserved word was causing a problem.
    variable v_refcursor refcursor;
    set autoprint on;
    begin 
         crosstab.pivot (p_max_cols => 4,
                 p_query => 
                   'SELECT job, COUNT (*) cnt, deptno, ' || 
                   '       ROW_NUMBER () OVER ( ' || 
                   '          PARTITION BY job ' || 
                   '          ORDER BY deptno) rn ' || 
                   'FROM   emp ' ||
                   'GROUP BY job, deptno',
                   p_anchor => crosstab.tarray ('JOB'),
                   p_pivot => crosstab.tarray ('DEPTNO', 'CNT'),
                   p_cursor => :v_refcursor);
    end;
    /Was going to use this package as a stored procedure in forms but I not sure it's going to work now.

  • Ref cursors and dynamic sql..

    I want to be able to use a fuction that will dynamically create a SQL statement and then open a cursor based on that SQL statement and return a ref to that cursor. To achieve that, I am trying to build the sql statement in a varchar2 variable and using that variable to open the ref cursor as in,
    open l_stmt for refcurType;
    where refcurType is a strong ref cursor. I am unable to do so because I get an error indication that I can not use strong ref cursor type. But, if I can not use a strong ref cursor, I will not be able to use it to build the report based on the ref cursor because Reports 9i requires strong ref cursors to be used. Does that mean I can not use dynamic sql with Reports 9i ref cursors? Else, how I can do that? Any documentation available?

    Philipp,
    Thank you for your reply. My requirement is that, sometimes I need to construct a whole query based on some input, and sometimes not. But the output record set would be same and the layout would be more or less same. I thought ref cursor would be ideal. Ofcourse, I could do this without dynamic SQL by writing the SQL multiple times if needed. But, I think dynamic SQL is a proper candidate for this case. Your suggestion to use lexical variable is indeed a good alternative. In effect, if needed, I could generate an entire SQL statement and place in some place holder (like &stmt) and use it as a static SQL query in my data model. In that case, why would one ever need ref cursor in reports? Is one more efficient over the other? My guess is, in the lexical variable case, part of the processing (like parsing) is done on the app server while in a function based ref cursor, the entire process takes place in the DB server and there is probably a better chance for re-use(?)
    Thanks,
    Murali.

  • Ref cursor and dynamic sql

    Hi..
    I'm using a ref cursor query to fetch data for a report and works just fine. However i need to use dynamic sql in the query because the columns used in the where condition and for some calculations may change dynamically according to user input from the form that launches the report..
    Ideally the query should look like this:
    select
    a,b,c
    from table
    where :x = something
    and :y = something
    and (abs(:x/:y........)
    The user should be able to switch between :x and :y
    Is there a way to embed dynamic sql in a ref cursor query in Reports 6i?
    Reports 6i
    Forms 6i
    Windows 2000 PRO

    Hello Nicola,
    You can parameterize your ref cursor by putting the query's select statement in a procedure/function (defined in your report, or in the database), and populating it based on arguments accepted by the procedure.
    For example, the following procedure accepts a strongly typed ref cursor and populates it with emp table data based on the value of the 'mydept' input parameter:
    Procedure emp_refcursor(emp_data IN OUT emp_rc, mydept number) as
    Begin
    -- Open emp_data for select all columns from emp where deptno = mydept;
    Open emp_data for select * from emp where deptno = mydept;
    End;
    This procedure/function can then be called from the ref cursor query program unit defined in your report's data model, to return the filled ref cursor to Reports.
    Thanks,
    The Oracle Reports Team.

Maybe you are looking for