Ref Cursors... Query

Hello,
I have created the package which uses the ref cursor.
I was able to compile the package.. I was not able to execute this package which calculates the sum of col1
====================================================
create table temp123 (col1 number, col2 varchar2(10), col3 date);
insert into temp123 values ( 1, 'A',sysdate-3);
insert into temp123 values ( 2, 'B',sysdate-2);
insert into temp123 values ( 3, 'C',sysdate-1);
insert into temp123 values ( 4, 'D',sysdate);
commit;
create or replace package asu123 as
type ref_def is record ( a_col temp123.col1%type,b_col temp123.col2%type, c_col temp123.col3%type);
type rec_type is ref cursor return ref_def;
function fun return rec_type;
end;
create or replace package body asu123 as
function fun return rec_type
as
a_rec rec_type;
begin
open a_rec for select * from temp123;
return a_rec;
end;
end;
If I execute the below sql, it will work fine...
select asu123.fun from dual;
COL1 COL2 COL3
1 A 04-NOV-04
2 B 05-NOV-04
3 C 06-NOV-04
4 D 07-NOV-04
=======================================================
Some how I need to execute this query as which sum's the COL1 field.
SELECT NVL (COUNT (*), 0) TOTALCOUNT,NVL (SUM (asu123.ref_def(sum(col1) ), 0) SUM_VALUE from dual;Any one have any inputs on this?. Thanks for your valuable feedback in advance.
--Binny

Either you are using cursor variables to solve the wrong problem or you are using them the wrong way. Consider these two different approaches. First, with REF CURSOR...
SQL> CREATE TABLE temp123 (col1 number, col2 varchar2(10), col3 date)
  2  /
Table created.
SQL> INSERT INTO temp123 VALUES ( 1, 'A',sysdate-3)
  2  /
1 row created.
SQL> INSERT INTO temp123 VALUES ( 2, 'B',sysdate-2)
  2  /
1 row created.
SQL> INSERT INTO temp123 VALUES ( 3, 'A',sysdate-1)
  2  /
1 row created.
SQL> INSERT INTO temp123 VALUES ( 4, 'A',sysdate)
  2  /
1 row created.
SQL> INSERT INTO temp123 VALUES ( 5, 'B',sysdate+1)
  2  /
1 row created.
SQL> INSERT INTO temp123 VALUES ( 6, 'B',sysdate+2)
  2  /
1 row created.
SQL> CREATE OR REPLACE PACKAGE asu123 AS
  2      --  in 9i we can use the predeclared sys_refcursor and skip this bit
  3      TYPE rec_type is ref cursor ;
  4      FUNCTION recs RETURN rec_type;
  5      FUNCTION sums RETURN rec_type;
  6  END;
  7  /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY asu123 AS
  2      FUNCTION recs RETURN rec_type
  3      AS
  4          a_rec rec_type;
  5      BEGIN
  6          OPEN a_rec FOR SELECT * FROM temp123;
  7          RETURN a_rec;
  8      END recs;
  9      FUNCTION sums RETURN rec_type
10      AS
11          a_rec rec_type;
12      BEGIN
13          OPEN a_rec FOR SELECT col2, COUNT (*) AS totalcount, sum(nvl(col1, 0)) AS sum_value 
14                         FROM temp123
15                         GROUP BY col2;
16          RETURN a_rec;
17      END sums;
18  END;
19  /
Package body created.
SQL> SELECT  asu123.recs FROM dual
  2  /
RECS
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
      COL1 COL2       COL3
         1 A          05-NOV-04
         2 B          06-NOV-04
         3 A          07-NOV-04
         4 A          08-NOV-04
         5 B          09-NOV-04
         6 B          10-NOV-04
6 rows selected.
SQL> SELECT  asu123.sums FROM dual
  2  /
SUMS
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
COL2       TOTALCOUNT  SUM_VALUE
A                   3          8
B                   3         13...versus using NESTED TABLE...
SQL> CREATE TYPE my_rec AS OBJECT (col1 number, col2 varchar2(10), col3 date);
  2  /
Type created.
SQL> CREATE TYPE my_tab AS TABLE OF my_rec;
  2  /
Type created.
SQL> CREATE OR REPLACE PACKAGE asu123 AS
  2      FUNCTION recs RETURN my_tab;
  3  END;
  4  /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY asu123 AS
  2      FUNCTION recs RETURN my_tab
  3      AS
  4          a_rec my_tab;
  5      BEGIN
  6          SELECT my_rec(col1, col2, col3) BULK COLLECT INTO a_rec
  7          FROM   temp123;
  8          RETURN a_rec;
  9      END recs;
10  END;
11  /
Package body created.
SQL> SELECT * FROM table(asu123.recs)
  2  /
      COL1 COL2       COL3
         1 A          05-NOV-04
         2 B          06-NOV-04
         3 A          07-NOV-04
         4 A          08-NOV-04
         5 B          09-NOV-04
         6 B          10-NOV-04
6 rows selected.
SQL> SELECT col2, COUNT (*) AS totalcount, sum(nvl(col1, 0)) AS sum_value
  2  FROM   table(asu123.recs)
  3  GROUP BY col2
  4  /
COL2       TOTALCOUNT  SUM_VALUE
A                   3          8
B                   3         13
SQL> Cheers, APC

Similar Messages

  • Cursors are not closed when using Ref Cursor Query in a report  ORA-01000

    Dear Experts
    Oracel database 11g,
    developer suite 10.1.2.0.2,
    application server 10.1.2.0.2,
    Windows xp platform
    For a long time, I'm hitting ORA-01000
    I have a 2 group report (master and detail) using Ref Cusor query, when this report is run, I found that it opens several cursors (should be only one cursor) for the detail query although it should not, I found that the number of these cursors is equal to the number of master records.
    Moreover, after the report is finished, these cursors are not closed, and they are increasing cumulatively each time I run the report, and finally the maximum number of open cursors is exceeded, and thus I get ORA-01000.
    I increased the open cursors parameter for the database to an unbeleivable value 30000, but of course it will be exceeded during the session because the cursors are increasing cumulatively.
    I Found that this problem is solved when using only one master Ref Cursor Query and create a breake group, the problem is solved also if we use SQL Query instead of Ref Query for the master and detail queries, but for some considerations, I should not use neither breake group nor SQL Query, I have to use REF Cursor queries.
    Is this an oracle bug , and how can I overcome ?
    Thanks
    Edited by: Mostafa Abolaynain on May 6, 2012 9:58 AM

    Thank you Inol for your answer, However
    Ref Cursor give me felxibility to control the query, for example see the following query :
    function QR_1RefCurDS return DEF_CURSORS.JOURHEAD_REFCUR is
    temp_JOURHEAD DEF_CURSORS.JOURHEAD_refcur;
              v_from_date DATE;
              v_to_date DATE;
              V_SERIAL_TYPE number;
    begin
    SELECT SERIAL_TYPE INTO V_SERIAL_TYPE
    FROM ACC_VOUCHER_TYPES
    where voucher_type='J'
    and IDENT_NO=:IDENT
    AND COMP_NO=TO_NUMBER(:COMPANY_NO);
         IF :no_date=1 then
                   IF V_SERIAL_TYPE =1 THEN     
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT
              AND ((TO_NUMBER(VOCH_NO)=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
              OR (TO_NUMBER(VOCH_NO) BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
              OR (TO_NUMBER(VOCH_NO)<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
              OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))
                   ORDER BY TO_NUMBER(VOCH_NO);
                   ELSE
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT               
              AND ((VOCH_NO=:FROM_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NULL)
              OR (VOCH_NO BETWEEN :FROM_NO AND :TO_NO and :FROM_NO IS NOT NULL AND :TO_NO IS NOT NULL )
              OR (VOCH_NO<=:TO_NO and :FROM_NO IS NULL AND :TO_NO IS NOT NULL )
              OR (:FROM_NO IS NULL AND :TO_NO IS NULL ))     
                   ORDER BY VOCH_NO;          
                   END IF;
         ELSE
                   v_from_date:=to_DATE(:from_date);
                   v_to_date:=to_DATE(:to_date);                         
              IF V_SERIAL_TYPE =1 THEN
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
              AND IDENT=:IDENT                         
                   AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
                   OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
                   OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
                   OR (:from_date is null and :to_date is null ))     
                   ORDER BY VOCH_DATE,TO_NUMBER(VOCH_NO);     
              ELSE
                   open temp_JOURHEAD for select VOCH_NO, VOCH_DATE
                   FROM JOURHEAD
                   WHERE COMP_NO=TO_NUMBER(:COMPANY_NO)
                   AND IDENT=:IDENT                         
              AND ((voch_date between v_from_date and v_to_date and :from_date is not null and :to_date is not null)
                   OR (voch_date <= v_to_date and :from_date is null and :to_date is not null)
                   OR (voch_date = v_from_date and :from_date is not null and :to_date is null)
                   OR (:from_date is null and :to_date is null ))     
                   ORDER BY VOCH_DATE,VOCH_NO;          
              END IF;
         END IF;               
         return temp_JOURHEAD;
    end;

  • How to write REF-CURSOR Query in Oracle Reports

    Hello Guys!!
    I have a form in which you can select regions/divisions/locations etc by the use of check boxes. And the selected values will be inserted into a table, and based on the selected values of the table the report is run.
    The issue I have is with the query inside the Oracle reports(attached to this file).
    The query works fine until the last two EXISTS conditions.
    IF a region exists In the table report_param then it works fine but if there are no divisions in it , then the query returns no values, which is not correct.
    Someone has advised me to use a ref-cursor query inside reports tool, which I am not aware off. So, anykind of suggestions or advises are welcome. Please let me know about it as it is very urgent issue for me. Anykind of help would be greatly
    appreciated.
    Thanks,
    Vishal
    -------------------------------------------------------Query in Oracle Reports---------------------------------------------------------
    select c.key_segment, p.supplier_id,
    decode(:in_col_nm, 'BRAND',nvl(p.product_brand,'<Unknown Brand>'), 'PLN',nvl(p.product_legal_name,'<Unknown Legal Name>')) COL_NM,
    sum(a.ext_price) sales_dols,
    sum(comp_allow_pkg.get_comp_allow_stddiv(a.control_loc_id, a.product_id, a.sold_to_customer_id,
    a.doc_dt, a.ext_price, a.units)) cust_reb_dols,
    sum(a.units) units,
    sum(a.ext_cost) cost_dols
    from sales a, key_segment_plns c, product p, rep_wrtr_dw_cust h
    where a.doc_dt between :in_start_dt and :in_end_dt
    and a.customer_oc = h.control_loc_id
    and a.sold_to_customer_id = h.sold_to_cust_id
    and a.ship_to_customer_id = h.ship_to_cust_id
    and ((:in_dg_cd = 'B' and h.dealer_grower_cd in ('D','G')) or h.dealer_grower_cd = :in_dg_cd)
    and a.product_id = p.product_id
    and p.product_gl_class_cd = 'CHEM'
    and p.product_legal_name = c.product_legal_name
    and c.key_segment in ('GLYPHOSATE','PLANT HEALTH/RUST FUNGICIDES','PYRETHROIDS','STROBI FUNGICIDES')--&IN_KEY_SEGMENTS
    -- and (:in_oc = 'ALL' or (a.control_loc_id in (select control_loc from control_loc_comb_ocs where control_loc_comb = :in_oc)))
    -- SALES DATA FILTERS TO MATCH ACCUM_SALES_DG_MV
    and a.sale_type_cd in ('02','08')
    and a.document_type_cd in ('I','C','D')
    and (substr(a.product_id,-1) in ('0','1') OR nvl(upper(trim(p.product_brand)),'X') = 'TECH FEE')
    and a.units <> 0
    and a.unit_cost <> 0
    and a.unit_price <> 0
    -- NEW FILTERS ADDED 9/11/07: LOCATION(BRANCH), BUSINESS TYPE, RSM/ASM/REP
    and ((:in_loc = 'ALL') or (nvl(a.warehouse_id,'<blank>') in (SELECT param_value
    FROM report_param
    WHERE report_id = :IN_REPORT_ID
    AND session_id= :IN_SESSION_ID
    AND USER_ID = :IN_USER_ID
    AND param_name='LOCATION_TYPE')))
    and ((:in_uhs_ag = 'ALL') or (:in_uhs_ag = 'NA' and p.product_uhs_ag != 'A') or (p.product_uhs_ag = :in_uhs_ag))
    and ((:in_sales_rep = 'ALL') or (nvl(a.territory_id,'<blank>') in (SELECT param_value
    FROM report_param
    WHERE report_id = :IN_REPORT_ID
    AND session_id= :IN_SESSION_ID
    AND USER_ID = :IN_USER_ID
    AND param_name='SALES_REP_TYPE')))
    and EXISTS
    (SELECT '1'
    FROM locations l, report_param rp
    WHERE rp.report_id = :IN_REPORT_ID
    AND rp.session_id= :IN_SESSION_ID
    AND rp.user_id = :IN_USER_ID
    AND rp.param_value = l.region
    AND rp.param_name = 'REGION_TYPE'
    AND a.warehouse_id = L.ARS_LOCATION)
    and EXISTS
    (SELECT '1'
    FROM locations l, report_param rp
    WHERE rp.report_id = :IN_REPORT_ID
    AND rp.session_id= :IN_SESSION_ID
    AND rp.user_id = :IN_USER_ID
    AND rp.param_value = l.region
    AND rp.param_name = 'DIVISION_TYPE'
    AND a.warehouse_id = L.ARS_LOCATION)
    group by c.key_segment, P.supplier_id,
    decode(:in_col_nm, 'BRAND',nvl(p.product_brand,'<Unknown Brand>'), 'PLN',nvl(p.product_legal_name,'<Unknown Legal Name>'))

    Hi,
    I need your help to create a report using Ref-Cursor. please see the below thread
    Report using ref cursor or dynamic Sql

  • Ref Cursor Query

    I was exploring the use of a ref cursor query within my report. The question that I have is do you have to put the package in the reports program units or can you place the package on the db server and call the package?

    Hi,
    You can do it both ways.
    Regards
    Kamal

  • Link Query and Ref Cursor Query

    Hi all!!
    How can I link Query and Ref Cursor Query??
    I mean, How can I pass input parameters to the PL/SQL procedure if they are not User parameters but they come from another table??
    Thanks a lot
    F.

    I have searched the forum and this is the closest to my problem.
    Just started using ref cursors in my reports.
    The problem I am running into is that I have two ref cursor queries in my report - they each contain a column named seq_no which forms a join (in the database) .
    My report returns the correct number of records in each query, but I can't find a way to enforce the join. I've tried all the methods I can think of including combining the results into one query.
    The IDE won't let me join on a column and when I join on the group (which I make only contain the seq_no fields) that join is ignored.
    Can anyone help me on this?

  • Dynamic queries in report builder 6i ( ref cursor query )

    Hi everyone,
    My requirement is that I want to create a report where the query is dynamic. The dynamic part will be known at runtime as it is being passed via a parameter. My query looks like this :
    select * from emp where sal :p1 :p2
    Possible values for :p1 are - '>', '<', '>=', '<=', '=', '!='
    Possible values for :p2 are - any value entered by the user
    I tried creating a query in report builder based on a ref cursor. But it does not allow me to create the query for the ref cursor dynamically. That means I have to hardcode the query in the program.
    I tried using place holder columns without success.
    Can someone please help me ?
    Regards,
    Al

    Hi,
    You can use lexical paramters in the sql query
    x - char - parameter
    select * from emp &x
    you need to pass the value for x in the parameter as
    'where sal < 1234'.
    Note : Lexical variable should be of char datatype.
    This is an alternative to the ref cursors.
    This works. Hope this is clear.

  • Help about writing a ref cursor query

    I can't see what's wrong about this query (the problem seems to be in 'where CO_MSDN_V >= '':p_MSISDN'' '):
    v_Query := 'select env.SQ_ECL_01, env.CO_MSDN_V, env.CO_IMSI_V, sms.CO_TEXT_V, env.CO_MSC_V, per.DS_PER_CLT_V, env.CO_REIN_N, TO_CHAR(env.FX_FECH_ENV_D, ''DD/MM/YYYY HH24:MI:SS''), TO_CHAR(env.FX_RCP_IAS_D, ''DD/MM/YYYY HH24:MI:SS'') ' ||
    'from (select /*+INDEX(ir_tb_env_clts,IN_PK_ENV_CLTS)*/ ' ||
    'SQ_ECL_01, CO_MSDN_V, CO_IMSI_V, CO_SMS_N, CO_MSC_V, CO_PER_CLT_N, CO_REIN_N, FX_FECH_ENV_D, FX_RCP_IAS_D ' ||
    'from ir_tb_env_clts ' ||
    'where CO_MSDN_V >= '':p_MSISDN'' ' ||
    'and FX_FECH_ENV_D >= :p_DATE ' ||
    'and CO_IMSI_V >= :p_IMSI '||
    'and SQ_ECL_01 > :p_SEQUENCE ' ||
    'and rownum <= :p_NUMROWS) env, ir_ct_sms sms, ir_ct_per_clt per ' ||
    'where env.CO_PER_CLT_N = per.CO_PER_CLT_N(+) ' ||
    'and env.CO_SMS_N = sms.CO_SMS_N(+) ' ||
    'order by env.CO_MSDN_V, env.FX_FECH_ENV_D, env.CO_IMSI_V, env.SQ_ECL_01 ';
    OPEN v_AllSendClients FOR v_Query USING p_MSISDN, v_DATE, p_IMSI, p_SEQUENCE, p_PageSize;
    When I call the procedure it is included in, I get the ORA-01001 error
    If I write 'where CO_MSDN_V >= :p_MSISDN ' I don't get the error, but it doens't do what I want

    Here are some additional examples that may help clarify. Notice, in the last example, that if the variable is declared as varchar2, it is treated as varchar2, not number, even without quotes.
    scott@ORA92> -- test data:
    scott@ORA92> SELECT * FROM ir_tb_env_clts
      2  /
    CO_MSDN_V
    35899995000
    34900000001
    scott@ORA92> -- where 35 is a character:
    scott@ORA92> select min(CO_MSDN_V)
      2  from ir_tb_env_clts
      3  where CO_MSDN_V >= '35'
      4  /
    MIN(CO_MSDN_V)
    35899995000
    scott@ORA92> -- where 35 is a number:
    scott@ORA92> select min(CO_MSDN_V)
      2  from ir_tb_env_clts
      3  where CO_MSDN_V >= 35
      4  /
    MIN(CO_MSDN_V)
    34900000001
    scott@ORA92> -- where co_msdn_v is a number:
    scott@ORA92> variable co_msdn_v number
    scott@ORA92> exec :co_msdn_v := 35
    PL/SQL procedure successfully completed.
    scott@ORA92> select min(CO_MSDN_V)
      2  from ir_tb_env_clts
      3  where CO_MSDN_V >= :co_msdn_v
      4  /
    MIN(CO_MSDN_V)
    34900000001
    scott@ORA92> -- where co_msdn_v is a character:
    scott@ORA92> variable co_msdn_v varchar2(20)
    scott@ORA92> exec :co_msdn_v := '35'
    PL/SQL procedure successfully completed.
    scott@ORA92> select min(CO_MSDN_V)
      2  from ir_tb_env_clts
      3  where CO_MSDN_V >= :co_msdn_v
      4  /
    MIN(CO_MSDN_V)
    35899995000

  • 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.

  • Dynamic Ref Cursor report in 6i

    Hello,
    I apologise that this question is so similar to many in this forum, but I haven't found a solution to my problem yet.
    I've created a ref cursor query because I need to include a variable p_orgs in my WHERE clause, like so:
    where e.org_id in ('||p_orgs||')
    I've constructed the report as mentioned on this page:
    www.dulcian.com
    FAQs - SQL & PL/SQL FAQs - FAQ ID# 5:
    "How can you use 'dynamic' ref cursors in Oracle Reports 3.0 / 6i?"
    (Thanks to Zlatko Sirotic for the information).
    I get a compile error when compiling the package body that holds my ref cursor open statement:
    Error 103 Encountered the symbol ''select'' when expecting one of the following:
    Select
    Is there any way around this problem?
    If I was to upgrade to Reports 9i would it work?
    Many thanks,
    Hazel

    Hello,
    Just a remark : you don't need to use a Ref Cursor if you just want to use a "dynamic where clause".
    You can use a lexical reference :
    You can find examples at :
    http://www.oracle.com/webapps/online-help/reports/10.1.2/topics/htmlhelp_rwbuild_hs/rwwhthow/whatare/dmobj/sq_a_lexical_references.htm
    (This page is about Reports 10.1.2 but Lexical references are identical in Reports 6i and Reports 10.1.2)
    Regards

  • REF Cursor in Reports 3.0.5.8

    I have developed a report (REPORTS 3.0.5.8)based on REF Cursor
    Query. I Created a local Package and called the function in the
    package in the QR_1RefCurDS function. I am able to get the
    results when I tried to run from my machine.
    The report was compiled, saved and generated and copied the REP
    file on to a different machine on the N/W.
    But when I tried to access the same report over the network, it
    fails giving the following error:
    REP-1401: 'beforereport': Fatal PL/SQL error occured.
    ORA-06508: PL/SQL: could not find the program unit being called.
    Runtime Engine and REP file reside on a single machine and I
    access the report in the following format:
    //Computer Name/Oracle_Home/Bin/R30RUN32.EXE //Computer
    Name/D/ReportName.Rep userid/password@SID
    I have been unsuccessful after trying to move the package to the
    database(I get a Virtual memory error ! !)
    Is there any other way to accomplish the same task(dynamic
    changing of the SQL statements) ?? Is LEXICAL Parameters is the
    only answer apart from the REF Cursor which does not work ?????
    Database:
    Oracle Server Release 7.3.4.3.0
    Oracle PL/SQL V2.3.4.3.0 Production Release
    Reports 3.0.5.8:
    Oracle Server Release 7.3.4.0.0
    Oracle PL/SQL V2.3.4.0.0 Production Release
    Does this make a difference ????
    Thanks a bunch...

    try recompiling the pll <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by kumaran:
    I am getting the following error when I try to run a report after upgrading from reports 3.0.5.8 to 3.0.5.12.2 on UNIX.
    I am able to successfully generate the rep file.
    but I am not able to run it. the report references a library(pll file) and this library is in the reports30_path
    ORA-06508: PL/SQL: could not find program unit being called
    any suggestions would be greately appreciated
    Thanks<HR></BLOCKQUOTE>
    null

  • Reports 3.0, Ref Cursor from stored procedure

    I have a problem trying to use Ref Cursor as datasource (i.e.
    Ref Cursor Query) in Reports 3.0
    I have created a stored package with a function which returns
    Ref Cursor.
    That function just opens the cursor and returns it to the
    calling module.
    Reports recognizes returned cursor - it creates a group for that
    query, with all columns, than I built
    a layout model - everything is OK on that stage.
    During the execution of that report (from previewer or using
    Reports Runtime) I got an error message like that:
    REP-0065 Virtual Memory System Error
    REP-0200 Cannot allocate enough memory cavaa22
    Error's description does not correspond the reality :) - there
    is enough virtual & physical memory according to
    Task Manager information.
    So, that does not work when this package is stored one.
    When I create the package on the client side - in Reports -
    everything works just fine.
    Cursor is opened with a very simple query, selecting records
    from the very simple table having only one record.
    There is no code written which closes that cursor or fetches the
    records.
    Client platform: WinNT 4.0 SP3
    Oracle Reports: 3.0.5.8.0
    Oracle Server: Oracle8 8.0.5.0.0 (and I tried also on Oracle7
    7.3.4.3.0)
    Thanx.
    null

    Sara,
    GTT (Global Temporary Tables) in Oracle work a different way compared to SQL Server and Informix. There you can create temporary tables on the fly and drop them on the fly.
    Here you should (note, you don't have to, but, best practice says that you should) create the table using the syntax...
    create global temporary table.....
    Once you create it, even though it looks like persistent table, it's not. It will have it's own individual data PER SESSION . You have two types of GTTs:
    ON COMMIT PRESERVE ROWS and ON COMMIT DELETE ROWS (they work in slightly different way).
    Look up GTTs here:
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14231/tables.htm#sthref2213
    HTH,
    Rahul

  • Ref Cursor on Report 6i

    I am trying to build a report based on Ref Cursor query with dynamic string as given below.
    OPEN loc_ref_cur_ugss_pay_car FOR 'SELECT name, email_id, job, remarks FROM employee_desc' ;
    On compile I am getting following error.
    Encountered the symbol "SELECT....." when expecting one of the following: select.
    Can't I use ref cursor with dynamic string?
    Thanks & regards,
    Rakesh

    If I will use Select statement without quote then it will be a static query. I want to use the dynamic one which will use different table names depending upon condition. The tables which are to be used here are temparary tables and will be be created through report only.

  • 6i report ref cursor exception no_data_found

    I have a simple report with one ref cursor query on a database packaged procedure.
    The Data Model function has an exception handler for no_data_found.
    The exception sets a local variable in a program unit spec.
    A field with a message based on a place holder column does not return.
    I am trying to give some message to the user & am not having luck.
    Ideas?
    Thank you.

    You can create a text field with the text "No data found".
    This field gets a format trigger
    if <your condition for no data found> then
      return true;
    else
      return false;
    end;

  • Ref.Cursor Problem - URGENT

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

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

  • Ref cursor help in Reports/pl sql

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

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

  • How to divide resultset of a query in different ref cursors in a package

    Hi Oracle Gurus,
    I need to create a package which counts the no of rows returned by a select query on multiple tables and according to the returned rowcount inputs the resultset in a ref cursor. Procedure will be called by a .NET program and output param refcursor will be assigned to a data reader which will redirect all the data to an Excel file.
    All the above is done. Issue is due to Excel's limit of 64000 rows, if data returned by query is greater than 64K it wont be fit in 1 Excel sheet. So, in order to overcome this limit I need to do some looping in Oracle package which keeps on storing the query results (rows<64K) in different ref cursors so that these refcursors as OUT params can be redirected to separate Excel sheets in C# program.
    NOTE : Earlier on I created 2 procedures in the package to fetch rows<64K and another one to fetch rows between 64K and rowcount of the query. My program was calling 2 different procedures to redirect data into 2 diff Excel sheets.
    But this fails when query resultset is even greater than 128000 or more and demands 3-4 or even more Excel sheets to be created.
    Please help.
    Any idea how to do looping in Oracle to accomplish this?

    > So, in order to overcome this limit I need to do some looping in Oracle package which keeps on
    storing the query results (rows<64K) in different ref cursors so that these refcursors as OUT params
    can be redirected to separate Excel sheets in C# program.
    Huh?
    That is saying that "I need to change this road and build it straight through that lake as the road has a curve here".
    It surely is a LOT easier to leave the road as is and simply turn the darn steering wheel in the car?
    Have the .Net data reader keep a row count of rows read from the ref cursor - and when it reached a pre-set max, have the reader do a "control break"[1] and change to a new worksheet as the destination for writing the rows to.
    [1] Google the term if you do not understand this basic concept that was among the very basic program control structures taught back in the 80's.. while I foam at the mouth how today's "wonder kids" turned programmers, that grew up with computers, do not even comprehend the most basic programming logic designs...

Maybe you are looking for