Function with dynamics cursor.

Hi everybody,
I'm trying to write a function having as argument as SQL query(or a part of it). This SQL query should generate a cusror within the function. All the way would have the generated cusror always the same structure.
CREATE OR REPLACE FUNCTION Calcul_avg(Name_Table VARCHAR) RETURN NUMBER
IS
TYPE Funct_Cursor_Type IS REF CURSOR RETURN Defined_Table%ROWTYPE;
Funct_Cursor Funct_Cursor_Type;
OPEN Funct_Cursor
FOR SELECT ID, NAME FROM Name_Table ;
Return Calcul_avg;
With this function,
I'm getting the error:
PLS-00455: cursor 'FUNCT_CURSOR' cannot be used in dynamic SQL OPEN statement
Thanks for your help!!
Alex

The error message measn what it says. We cannot use a strongly typed cursor with dynamic SQL. This is because the typing is enforced at compile time, whereas the cursor is only assembled at runtime. So we must use weakly typed cursors in this situation.
If you have 9i then you can use an instance of the pre-defined SYS_REFCURSOR. Else
TYPE Funct_Cursor_Type IS REF CURSOR;Cheers, APC

Similar Messages

  • 2 functions with one cursor or.. 1 function with 2 cursors?

    Hi friends,
    I hope you help me to decide is this easy question:
    Actually I have 2 functions. Both are the same more or less: Both get data from USERS table. (In the users table there are several columns, I'm interested in "code" and "description")
    Function1 have a cursor which obtain data and orders by code,
    Function2 have a cursor which obtain data and orders by description.
    That's the only difference.
    I want to "optimize" the code so I was thinking on creating only a function.
    To do the same in one only function I thinked on passing a parameter i.e.: p_ordertype to know which would be the order ("C" for code or "D" for description)
    In that function I would have two cursors and I would ask for the parameter to execute one "FOR...." or the other.
    The question: Would it be really effective? I think that if I have 2 cursors in a function... I would cosume more memory than if I would only have one cursor.. (because I think data selected from cursors is parsed to memory when you invoke the function, before the 1st instruction after the BEGIN is executed, isn't it?)
    Would it be better 2 functions with one cursor each one or... one function with 2 cursors?
    Thanks in advance for your opinions.
    Jose.

    Hi again Todd,
    there's a problem with you solution :
    Imagine you have the following users:
    usercode - userdescr
    1 - ALAN
    2 - RICHARD
    3 - DANI
    12 - CHARLIE
    20 - BARRY
    If we pass a 'C' as p_ordertype (to obtain the list like above, ordered by usercode) , the result would be:
    1 - ALAN
    12 - CHARLIE
    2 - RICHARD
    20 - BARRY
    3 - DANI
    Do you understand what i'm trying to explain?... I hope that... I tried with
    ORDER BY DECODE(p_ordertype,'C',usercode,'D',TO_NUMBER(userdescr));
    but it doesn't works...
    More ideas?

  • Create function with a cursor in it

    I need help to create a function called f_Getfeedesc. I want to use a cursor for Loop. The function will return fees description for any folder.
    If a folder has more than one fee description, it will concatenate the fees description.
    The select statement I have here returns the following fees description:
    CO Residential 3+ Units No Entry Penalty Fee
    C of O Initial Fee
    CO Residential 3+ Units Initial Fee
    However when the function is done if you run it using the folderrsn 99999 the result should look like this:
    CO Residential 3+ Units No Entry Penalty Fee / C of O Initial Fee / CO Residential 3+ Units Initial Fee
    If the folderrsn has only one fee description the result should just return that one fee description. e.g CO Residential 3+ Units No Entry Penalty Fee
    I am using the following tables:
    folder table with FOLDERRSN......... NOT NULL  NUMBER(10,0) column.
    accountbillfee table with FEECODE..........NOT NULL  NUMBER(10,0) column.
    validaccountfee table with FEECODE........NOT NULL  NUMBER(10,0) and FEEDESC............NOT NULL  VARCHAR2(80) columns.
    SELECT DISTINCT vaf.feedesc
    FROM folder f, accountbillfee abf, validaccountfee vaf
    WHERE f.folderrsn = abf.folderrsn
    AND vaf.feecode = abf.feecode
    --And f.folderrsn = argfolderrsn
    AND f.folderrsn = 99999 --for a specific folderrsn
    Edited by: user4653174 on Sep 12, 2008 1:31 PM

    Hi,
    What you're trying to do is called "string aggregation".
    There's an excellent page on AskTom with several general solutions.
    I recommend the first one, STRAGG.
    Once you have STRAGG installed, you can get the output you want as simply as this:
    SELECT    feecode
    ,         STRAGG (feedesc)
    FROM      validaccountfee
    GROUP BY  feecode;Edited by: Frank Kulash on Sep 13, 2008 2:56 AM

  • Running a function with a cursor output

    Hi All,
    It sounds like this should be easy, but I can't get it to work! I'm trying to run or debug a function in JDev. The function simply calls a Java SP that returns a cursor. This all works fine and it runs in SPL Plus with no problems. The problem is that when I try to run it from within JDev I get presented with the PL/SQL block window, and nothing I do will let me view the contents of the cursor returned - mostly I just get errors and the code doesn't run at all.
    The default code it generates is:
    DECLARE
    v_Return NULL;
    BEGIN
    v_Return := ALISI.POC.POCCALLSP();
    -- Modify the code to output the variable
    -- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
    END;
    I think this should be modified to say:
    DECLARE
    v_Return Types.ref_cursor;
    BEGIN
    v_Return := ALISI.POC.POCCALLSP();
    -- Modify the code to output the variable
    DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
    END;
    But the DBMS_OUTPUT.PUT_LINE is expecting a string, not a cursor, and nothing I've tried (I've tried so many things I can't begin to list them - or remember them) will work.
    Can anyone point out the error in my ways? Is it anything to do with the fact that I'm using a function and not a procedure? As you can probably tell I'm new to all this!
    Many thanks,
    John.

    With "simple" variables, we are able to display the output using DBMS_OUTPUT. For composite variables (PL/SQL tables, PL/SQL records, cursors, etc), there's no good way for us to directly display the result. DBMS_OUTPUT.PUT_LINE can only take a "String", or something that can be converted to it, and unlike Java, not everything implements a toString method. We would expect in such cases that the user modify the code as desired to output the data.
    That being said, you are actually encountering a bug here. With most datatypes that we can't display directly, we generally get enough information that we generate code that at least compiles and runs. I've logged a bug (3124777) to track this.
    (For what it's worth, I've tried this in 9.0.5, only to discover that the functionality has regressed a bit to be even less correct than in 9.0.3.)
    After the bug is fixed the output should look like this:
    DECLARE
      v_Return Types.ref_cursor; -- assuming this is the name of your ref cursor type
    BEGIN
      v_Return := ALISI.POC.POCCALLSP();
      -- Modify the code to output the variable
      -- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
    END;The user would then need to modify the part that displays the output. In this example, it might go something like this:
    DECLARE
      v_Return Types.ref_cursor; -- assuming this is the name of your ref cursor type
      v_Record v_Return%ROWTYPE;
    BEGIN
      v_Return := ALISI.POC.POCCALLSP();
      -- Modify the code to output the variable
      LOOP
        FETCH v_Return INTO v_Record;
        EXIT WHEN v_Return%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE (v_Record.employee_id || CHR(9) || v_Record.last_name
          || CHR(9) || v_Record.salary); -- replace with your field names
      END LOOP;
    END;I hope this helps!
    -- Brian

  • BETWEEN FUNCTION WITH IN A DECODE FUNTION IN A CURSOR

    The following below is my query..I have to get the hours,min and seconds from a 'yyyy-mm-dd-24hh.mi.ss' value and check if the time is between 12 am to 6 am , then write it with one value else write an another value..I am trying to use 'BETWEEN' function in decode function but i am getting error.....Can we use BETWEEN function with in decode function or is there any other way
    set serveroutput on
    declare
    cursor cur_dte is select lst_upd_date from EMPLOYESS ;
    begin
    for i in cur_dte loop
    DECODE (substr(trim(i.lst_upd_date),12)) ,between '00.00.00.0000' and '06.00.00.00.0000' ,101,102);
    dbms_output.put_line(i.lst_upd_date);
    end loop;
    end

    First of all. If you are in PL/SQL then CASE is just a more colmplex expression then IF THEN ELSE. I usually prefere If then else, but for some rare cases.
    The other issue is that you convert a datetime value into a string. This is wrong. it opens up all possible kinds of cenversion bugs. Stay with date or timestamp as long as possible.
    The solution depends a little upon the datatype of your lst_upd_date column.
    Here is a pl/sql solution assuming it is DATE.
    The TRUNC function can be used to reduce a datetime to a day or to an hour.
    declare
       cursor cur_dte is select lst_upd_date from employees ;
    begin
       for i in cur_dte loop
         if trunc(i.lst_upd_date,'HH') between trunc(i.lst_upd_date) and trunc(i.lst_upd_date)+6/24 then
            dbms_output.put_line(to_char(i.lst_upd_date,'DD-MON-YYYY HH24:MI:SS'));
         end if;       
       end loop;
    end;
    /But a pure SQL solution is much better.
    Here is how you implement it using CASE in SQL.
    example using pure sql
    select e.*,
            case when trunc(e.lst_upd_date,'HH')
                   between trunc(e.lst_upd_date) and trunc(e.lst_upd_date)+6/24
            then 101
            else 102
            end as "early_morning_check"
    from employees e;And if it is a timestamp column then you could use the EXTRACT function.
    select e.*,
            case when to_number(extract(hour from e.lst_upd_date))
                   between 0 and 6
            then 101
            else 102
            end as "early_morning_check"
    from employees e;You might want to consider if date values like 06:45:00 should be included or not.

  • Parallel  piplelined function not parallelizing with ref cursor

    RDBMS 11.2.0.3
    I have a function with the following signature
    function to_file (
      p_source     in  sys_refcursor
    , p_file_name  in  varchar2
    , p_directory  in  varchar2 default 'DD_DUMP'
    return dd_dump_ntt
    pipelined
    parallel_enable ( partition p_source by any )
    authid current_user;The function works in parallel when I use a cursor expression like this
    begin
      for rec in ( select *
                   from table(dd_dump.to_file( cursor(select /*+ parallel(i 4) */ c1||chr(9)||c2 from mytable i), 'f.out' ))
      loop
        dbms_output.put_line(rec.file_name || chr(9) || rec.num_records );
      end loop;
    end;
    f.out_162     276234
    f.out_213     280399
    f.out_230     286834
    f.out_70     289549But when I use a refcursor, it does not run in parallel
    declare
      rc sys_refcursor;
    begin
      open rc for 'select /*+ parallel(i 4) */ c1||chr(9)||c2 from mytable i';
      for rec in ( select *
                   from table(dd_dump.to_file( rc, 'f.out' ))
      loop
        dbms_output.put_line(rec.file_name || chr(9) || rec.num_records );
      end loop;
    end;
    f.out_914     1133016Is this an expected behavior or am I doing something wrong? How can I use the function when the client returns the SQL statement as a character string
    Edited by: Sanjeev Chauhan on Mar 9, 2012 11:54 AM

    Sanjeev Chauhan wrote:
    I am not performing any DML in the pipelined function. If you read the note carefuly it shows parallel_enable works only when you use:
    table(table_function(<font color=red>CURSOR</font>(select...)))and not when you use
    table(table_function(<font color=red>ref-cursor-name</font>))SY.

  • How to create a procedure function with a return value of ref cursor?

    Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
    I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
    Thanks a lot.

    http://osi.oracle.com/~tkyte/ResultSets/index.html

  • Will a new MotherBoar​d cure Blank Screen with blinking cursor?

    Stuck with Blank Screen with blinking cursor; ESC key couldn’t bring up Startup Menu; OS is not loading
    Product Name: HP G62 237 CA Notebook PC
    Short description of the problems:   
    --- Press ESC key couldn’t bring up Startup Menu when booting up
    --- Blank screen with blinking cursor thereafter
    --- Stuck here forever and OS is not loading
    DETAILED INFORMATION:
    Product Name and Operating System:      
    Model: HP G62 237 CA Notebook PC
    O/S: Pre-loaded with Win 7 Home Prem
    Processor: Pent. Dual-Core CPU T4500 2.30GHz
    Memory: 4GB
    BIOS Ver. (Insyde): F.17
    System BOARD ID: 1484
    Product #: WQ767UA#ABC
    Product Config ID: 049C110000202710000020000
    Problem History:     
    --- Used to have frequent BSOD (got fixed later because of faulty RAM that I suspected)
    --- Window couldn’t be loaded
    --- Window Repair and HP Recovery were tried but not functioning
    --- OEM Hard Drive was then removed & formatted few times by using other computer
    --- Hard Drive was then tested by other computer; it can be installed Win XP & Win 7
    --- So, Hard Drive was eliminated from the suspect list
    --- Replaced with other good RAM from other computers & put back the OEM Hard Drive to my HP G62; everything worked fine, such as: able to reinstall Win 7; listening to music files; got Internet to download latest BIOS from HP support site; connected to my 42 inched TV as my monitor; and even smoothly updated the BIOS from v.17 to v.37!
    --- Also, able to receive Window Updates from the Internet; and seemed that all problems were nicely solved
    --- Once I believe my system got stabilized; I went back to test the 2 supposedly problematic RAM to see whether they were both faulty or not, then the whole thing has turned around! Completely screwed me up until this moment …
    --- After put back the problematic RAM, Window couldn’t be loaded …
    --- With a few error messages… such as,
    --- The file is possibly corrupt. The file header checksum does not match the computed checksum;
    --- After the next reboot… an unexpected screen message showed up:
    Intel ® Cantiga PCI Accelerated SVGA BIOS
    Build Number: 1932 PC 14.34 11/11/2009 02:36:14
    DECOMPILATION OR DISASSEMBLY PROHIBITED
    Copyright © 2000-2003 Intel Corp. All Rights Reserved.
    --- After that, OS was not loading …
    --- Press ESC key couldn’t bring up the Startup Menu during boot up
    --- Blank screen with blinking cursor thereafter and seems stuck here forever
    Procedures performed for troubleshooting:
    Tried hard reset for more than 5 times (removed battery, AC adapter disconnected and then hold down the Power button for more than 60 secs) and tried reseating memory too; same result with Blank Screen with blinking cursor after each reboot.
    Connected to an external monitor [Fn + F4/F5] to see whether there was any display, nothing has showed on the external monitor, it seemed that no connection established between the two.
    Finally, took the long journey to follow the Service and Maintenance Guide of HP G62 to remove the CMOS battery for well over 15 minutes and put it back. But the result was again disappointed. Tried 4 times already. The latest error message is:      
    The CMOS checksum is invalid. The CMOS will be reset to the default configuration and will be rebooted. Please check your BIOS Setup options to see if they change.
    CMOS Reset (502)
    ENTER – Reboot the system
    After this message, the same Blank Screen with blinking cursor came back. And pressing the ESC key couldn’t bring up Startup Menu when booting up …
    Note: the fan is still running; the Power button is functioning but seems stuck here forever!
    I’ve already carefully read this HP Support document titled “HP BIOS Application Selected is Corrupt or Missing”:
    http://h10010.www1.hp.com/ewfrf/wc/document?cc=us&​lc=en&dlc=en&docname=c01443485#N144
    If really is the BIOS problems, then I will have the difficulties of updating a Window-based BIOS when I couldn’t even load Window!
    (Note: Boot from USB has no point because right now I couldn’t change the boot sequence because the various “Startup Menu” options are not showing up!)  
    Secondly, I am still stuck with the Blank Screen with a blinking cursor after I passed the first screen of “Press the ESC key for Startup Menu” when re-booted again!
    Thirdly, I have formatted my Hard Drive more than 3 times during the last few days for testing; I don’t have the OEM pre-loaded Win 7 with me anyone … and I don’t think I have the UEFI installed previously on my system. I did try hold down the Win Key + B with the most updated BIOS in the attached USB …, it came back with the same blank screen with a cursor blinking after reboot.
    Note: the Blank Screen I’m experiencing right now is not completely black, in fact, there is background light from behind the screen and on each reboot, I can see the HP logo and the left corner message of: “Press ESC key for Startup Menu” … So, I suppose that my computer screen is not physically broken at least.
    Requests:
    Please explain to me that what are the problem areas and the root causes if is possible?
    What steps or other tests can be done to make it work again?
    Do you think replacing the entire MotherBoard can cure the Blank Screen with blinking cursor?
    [Warranty: expired! I am the original purchaser & the end-user of this HP G62; acquired 2 years ago directly from a trustworthy source: staples (in Canada). Would HP Support still willing to service it for an extra charge?]
    Thanks in advance for any suggestion and idea!
    Owenson
    ===========================================

    Stuck with Blank Screen with blinking cursor; ESC key couldn’t bring up Startup Menu; OS is not loading
    Product Name: HP G62 237 CA Notebook PC
    Short description of the problems:   
    --- Press ESC key couldn’t bring up Startup Menu when booting up
    --- Blank screen with blinking cursor thereafter
    --- Stuck here forever and OS is not loading
    DETAILED INFORMATION:
    Product Name and Operating System:      
    Model: HP G62 237 CA Notebook PC
    O/S: Pre-loaded with Win 7 Home Prem
    Processor: Pent. Dual-Core CPU T4500 2.30GHz
    Memory: 4GB
    BIOS Ver. (Insyde): F.17
    System BOARD ID: 1484
    Product #: WQ767UA#ABC
    Product Config ID: 049C110000202710000020000
    Problem History:     
    --- Used to have frequent BSOD (got fixed later because of faulty RAM that I suspected)
    --- Window couldn’t be loaded
    --- Window Repair and HP Recovery were tried but not functioning
    --- OEM Hard Drive was then removed & formatted few times by using other computer
    --- Hard Drive was then tested by other computer; it can be installed Win XP & Win 7
    --- So, Hard Drive was eliminated from the suspect list
    --- Replaced with other good RAM from other computers & put back the OEM Hard Drive to my HP G62; everything worked fine, such as: able to reinstall Win 7; listening to music files; got Internet to download latest BIOS from HP support site; connected to my 42 inched TV as my monitor; and even smoothly updated the BIOS from v.17 to v.37!
    --- Also, able to receive Window Updates from the Internet; and seemed that all problems were nicely solved
    --- Once I believe my system got stabilized; I went back to test the 2 supposedly problematic RAM to see whether they were both faulty or not, then the whole thing has turned around! Completely screwed me up until this moment …
    --- After put back the problematic RAM, Window couldn’t be loaded …
    --- With a few error messages… such as,
    --- The file is possibly corrupt. The file header checksum does not match the computed checksum;
    --- After the next reboot… an unexpected screen message showed up:
    Intel ® Cantiga PCI Accelerated SVGA BIOS
    Build Number: 1932 PC 14.34 11/11/2009 02:36:14
    DECOMPILATION OR DISASSEMBLY PROHIBITED
    Copyright © 2000-2003 Intel Corp. All Rights Reserved.
    --- After that, OS was not loading …
    --- Press ESC key couldn’t bring up the Startup Menu during boot up
    --- Blank screen with blinking cursor thereafter and seems stuck here forever
    Procedures performed for troubleshooting:
    Tried hard reset for more than 5 times (removed battery, AC adapter disconnected and then hold down the Power button for more than 60 secs) and tried reseating memory too; same result with Blank Screen with blinking cursor after each reboot.
    Connected to an external monitor [Fn + F4/F5] to see whether there was any display, nothing has showed on the external monitor, it seemed that no connection established between the two.
    Finally, took the long journey to follow the Service and Maintenance Guide of HP G62 to remove the CMOS battery for well over 15 minutes and put it back. But the result was again disappointed. Tried 4 times already. The latest error message is:      
    The CMOS checksum is invalid. The CMOS will be reset to the default configuration and will be rebooted. Please check your BIOS Setup options to see if they change.
    CMOS Reset (502)
    ENTER – Reboot the system
    After this message, the same Blank Screen with blinking cursor came back. And pressing the ESC key couldn’t bring up Startup Menu when booting up …
    Note: the fan is still running; the Power button is functioning but seems stuck here forever!
    I’ve already carefully read this HP Support document titled “HP BIOS Application Selected is Corrupt or Missing”:
    http://h10010.www1.hp.com/ewfrf/wc/document?cc=us&​lc=en&dlc=en&docname=c01443485#N144
    If really is the BIOS problems, then I will have the difficulties of updating a Window-based BIOS when I couldn’t even load Window!
    (Note: Boot from USB has no point because right now I couldn’t change the boot sequence because the various “Startup Menu” options are not showing up!)  
    Secondly, I am still stuck with the Blank Screen with a blinking cursor after I passed the first screen of “Press the ESC key for Startup Menu” when re-booted again!
    Thirdly, I have formatted my Hard Drive more than 3 times during the last few days for testing; I don’t have the OEM pre-loaded Win 7 with me anyone … and I don’t think I have the UEFI installed previously on my system. I did try hold down the Win Key + B with the most updated BIOS in the attached USB …, it came back with the same blank screen with a cursor blinking after reboot.
    Note: the Blank Screen I’m experiencing right now is not completely black, in fact, there is background light from behind the screen and on each reboot, I can see the HP logo and the left corner message of: “Press ESC key for Startup Menu” … So, I suppose that my computer screen is not physically broken at least.
    Requests:
    Please explain to me that what are the problem areas and the root causes if is possible?
    What steps or other tests can be done to make it work again?
    Do you think replacing the entire MotherBoard can cure the Blank Screen with blinking cursor?
    [Warranty: expired! I am the original purchaser & the end-user of this HP G62; acquired 2 years ago directly from a trustworthy source: staples (in Canada). Would HP Support still willing to service it for an extra charge?]
    Thanks in advance for any suggestion and idea!
    Owenson
    ===========================================

  • In mail, I am having trouble with my cursor.  It doesn't "land" where I think I'm putting it.  It usually "lands" somewhere below where I "click" it to be.

    In Mail, I am having trouble with my cursor.  When making revisions to what I have already typed, the cursor doesn't "land" where I "click" it to be.  It seems to land somewhere below the spot I click on. It seems to have a mind of its own. 

    Cool handyandy42!
    I'm happy I could be helpful, with solving your problem!
    Also, I notice that you have marked your question as answered, but have not utilized the Helpful or Solved options. That may be intentional, but, if you are not aware of the benefits, of using that function, here is some information.
    When you mark the appropriate posts as Helpful (5 pts) 2 available, or Solved (10 pts) 1 available, you are Thanking the contributors, by awarding them points.
    In threads with multiple replies, it also alerts other readers, to which answers may have been helpful, or solved the issue.
    This info, and more, can be viewed by clicking on
    ? Help & Terms of Use, located under your login name, on all "Discussions" pages.
    Specifically What are question answers?.
    ali b

  • Database selection with Invalid Cursor error in RSDRI_INFOPROV_READ

    Hi Everyone.
    I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
    Logic of the code is as following
    while <more data>
    CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
    Append lines of E_T_DATA to EO_T_DATA.
    If total lines of data in EO_T_DATA > 200000
    <save EO_T_DATA in a file using GUI_DOWNLOAD>
    <clear EO_T_DATA>
    EndIF
    EndWhile.
    As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
    Error says "Database selection with invalid cursor".
    I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
    But it is imperative for me to save data in file at regular intervals as data volume is huge.
    Any pointers in this direction will be helpful.

    Hi Everyone.
    I am using RSDRI_INFOPROV_READ Function module for reading data from a multiprovider.
    Logic of the code is as following
    while <more data>
    CALL RSDRI_INFOPROV_READ reading data in E_T_DATA
    Append lines of E_T_DATA to EO_T_DATA.
    If total lines of data in EO_T_DATA > 200000
    <save EO_T_DATA in a file using GUI_DOWNLOAD>
    <clear EO_T_DATA>
    EndIF
    EndWhile.
    As soon as number of record exceed 200000 first file is saved, but after that next data call results in error.
    Error says "Database selection with invalid cursor".
    I suspect that this because of call to FM GUI_DOWNLOAD. While calling this FM after RSDRI_INFOPROV_READ causes system to commit and again the cursor is tried to open in next call casuing it to fail.
    But it is imperative for me to save data in file at regular intervals as data volume is huge.
    Any pointers in this direction will be helpful.

  • How to create a function with ref_cursor as parameter in OWB 10.1

    Hi,
    Can any one help me how to create a function with ref_cursor as parameter in OWB 10.1.?
    Its urgent. Please help me.
    Thanks,
    Siv

    Hi David,
    Thanks for your reply.
    Before going for this function, I need to create a package in transformation node in owb module.
    My package is as follows,
    Create or replace package 123
    type xxx is RECORD ( parameters);
    type yyy is RECORD (parameters);
    type aaa is table of yyy;
    type bbb is REF CURSOR return xxx;
    type ccc is record (parameters);
    type ddd is ref cursor return eee;
    END;
    How can I create the above kind of package manually in OWB 10.1 (Should not to import the package)
    Please help me its urgent.
    Thanks,
    Siv

  • No function with name 'F_ITEMCHECK' exists in this scope

    Hi i have a error:
    SQL> Declare
    2 Cursor stk_val is
    3 Select prod_code,prod_desc, bal_Stock from prod_tran;
    4 mProd_code prod_tran.prod_Code%type;
    5 mProd_desc prod_tran.prod_desc%type;
    6 mProd_qty prod_tran.prod_qty%type;
    7 valexits integer;
    8 bal_stock integer;
    9 vquantity integer;
    10 f_itemcheck integer;
    11 Begin
    12 Open stk_val;
    13 loop
    14 Fetch stk_val into mprod_code,mprod_desc,mprod_qty;
    15 exit when stk_val%notfound;
    16 valexits := f_itemcheck(mprod_code);
    17 if valexits = 0 then
    18 insert into prod_mast(prod_code,prod_Desc,bal_Stock)
    19 values(mprod_code,mprod_Desc,mprod_qty);
    20 elsif valexits = 1 then
    21 update prod_mast
    22 set bal_stock = bal_stock+ vquantity
    23 where prod_code=mprod_code;
    24 end if;
    25 end loop;
    26 close stk_Val;
    27 end;
    28 /
    Declare
    ERROR at line 1:
    ORA-06550: line 3, column 34:
    PLS-00320: the declaration of the type of this expression is incomplete or malformed
    ORA-06550: line 3, column 6:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 16, column 22:
    PLS-00222: no function with name 'F_ITEMCHECK' exists in this scope
    ORA-06550: line 16, column 10:
    PL/SQL: Statement ignored

    May be try this code
    Declare
      Cursor stk_val is
      Select prod_code,prod_desc, bal_Stock
        from prod_tran;
      v_prod stk_val%rowtype;
      valexits    integer;
      bal_stock   integer;
      vquantity   integer;
    Begin
      Open stk_val;
      loop
        Fetch stk_val into v_prod;
        exit when stk_val%notfound;     
        valexits := f_itemcheck(v_prod.prod_code);
        if valexits = 0 then       
          insert into prod_mast(prod_code,prod_Desc,bal_Stock)
          values(v_prod.prod_code,v_prod.prod_Desc,v_prod.prod_qty);
        elsif valexits = 1 then
          update prod_mast
             set bal_stock = bal_stock+ vquantity
           where prod_code=v_prod.prod_code;
        end if;
      end loop;
      close stk_Val;
    end;Note: Code untested

  • Pipelined Function with execute immediate

    Hello Experts,
    I have created a Pipe lined function with execute immediate, due to below requirement;
    1) Columns in where clause is passed dynamically.
    2) I want to know the data stored into above dynamic columns.
    3) I want to use it in report, so I don't want to insert it into a table.
    I have created a TYPE, then through execute immediate i have got the query and result of that query will be stored in TYPE.
    But when calling the function i am getting
    ORA-00932: inconsistent datatypes: expected - got -
    Below is my function and type, let me know i am going wrong, and is my logic correct.
    CREATE OR REPLACE TYPE OBJ_FPD AS OBJECT
                      (LOW_PLAN_NO VARCHAR2 (40),
                       FPD VARCHAR2 (5),
                       SERIAL_NO NUMBER,
                       CEDIA_CODE VARCHAR2 (2),
                       DT DATE);
    CREATE OR REPLACE TYPE FPD_TBL_TYPE AS TABLE OF OBJ_FPD;
    CREATE OR REPLACE FUNCTION FUNC_GET_FPD_DATE (P_LOW_PLAN_NO    VARCHAR2,
                                                  P_CEDIA_CODE     VARCHAR2,
                                                  P_SERIAL_NO      NUMBER)
       RETURN FPD_TBL_TYPE
       PIPELINED
    AS
       CURSOR C1
       IS
              SELECT 'FPD' || LEVEL TBL_COL
                FROM DUAL
          CONNECT BY LEVEL <= 31;
       V_STR        VARCHAR2 (5000);
       V_TBL_TYPE   FPD_TBL_TYPE;
    BEGIN
       FOR X IN C1
       LOOP
          V_STR :=
                'SELECT A.low_PLAN_NO,
               A.FPD,
               A.SERIAL_NO,
               A.cedia_code,
               TO_DATE (
                     SUBSTR (FPD, 4, 5)
                  || ''/''
                  || TO_CHAR (C.low_PLAN_PERIOD_FROM, ''MM'')
                  || ''/''
                  || TO_CHAR (C.low_PLAN_PERIOD_FROM, ''RRRR''),
                  ''DD/MM/RRRR'')
                  DT FROM ( SELECT low_PLAN_NO, '
             || ''''
             || X.TBL_COL
             || ''''
             || ' FPD, '
             || X.TBL_COL
             || ' SPTS, SERIAL_NO, cedia_code FROM M_low_PLAN_DETAILS WHERE NVL('
             || X.TBL_COL
             || ',0) > 0 AND SERIAL_NO = '
             || P_SERIAL_NO
             || ' AND cedia_code = '
             || ''''
             || P_CEDIA_CODE
             || ''''
             || ' AND low_PLAN_NO = '
             || ''''
             || P_LOW_PLAN_NO
             || ''''
             || ') A,
               M_low_PLAN_DETAILS B,
               M_low_PLAN_MSTR C
         WHERE     A.low_PLAN_NO = B.low_PLAN_NO
               AND A.cedia_code = B.cedia_code
               AND A.SERIAL_NO = B.SERIAL_NO
               AND B.low_PLAN_NO = C.low_PLAN_NO
               AND B.CLIENT_CODE = C.CLIENT_CODE
               AND B.VARIANT_CODE = C.VARIANT_CODE
    CONNECT BY LEVEL <= SPTS';
          EXECUTE IMMEDIATE V_STR INTO V_TBL_TYPE;
          FOR I IN 1 .. V_TBL_TYPE.COUNT
          LOOP
             PIPE ROW (OBJ_FPD (V_TBL_TYPE (I).LOW_PLAN_NO,
                                V_TBL_TYPE (I).FPD,
                                V_TBL_TYPE (I).SERIAL_NO,
                                V_TBL_TYPE (I).CEDIA_CODE,
                                V_TBL_TYPE (I).DT));
          END LOOP;
       END LOOP;
       RETURN;
    EXCEPTION
       WHEN OTHERS
       THEN
          RAISE_APPLICATION_ERROR (-20000, SQLCODE || ' ' || SQLERRM);
          RAISE;
    END;Waiting for your views.
    Regards,

    Ora Ash wrote:
    Hello Experts,
    I have created a Pipe lined function with execute immediate, due to below requirement;
    1) Columns in where clause is passed dynamically.No, that's something you've introduced, and is due to poor database design. You appear to have columns on your table called FPD1, FPD2 ... FPD31. The columns do not need to be 'passed dynamically'
    2) I want to know the data stored into above dynamic columns.And you can know the data without it being dynamic.
    3) I want to use it in report, so I don't want to insert it into a table.That's fine, though there's no reason to use a pipelined function.
    You also have an pointless exception handler, which masks any real errors.
    I'm not quite sure what the point of your "connect by" is in your query as we don't have your tables or data or know for sure what the expected output is.
    However, in terms of handling the 'dynamic' part that you've introduced, then you would be looking at doing something along the following lines, using a static query that requires no poor dynamic code, and no pipelined function...
    with x as (select level as dy from dual connect by level <= 31)
    select a.low_plan_no
          ,a.fpd
          ,a.serial_no
          ,a.cedia_code
          ,trunc(c.low_plan_period_from)+a.dy-1 as dt
    from  (select low_plan_no
                 ,dy
                 ,'FPD'||dy as fpd
                 ,spts
                 ,serial_no
                 ,cedia_code
           from (
                 select low_plan_no
                       ,x.dy
                       ,case x.dy when 1 then fpd1
                                  when 2 then fpd2
                                  when 3 then fpd3
                                  when 4 then fpd4
                                  when 5 then fpd5
                                  when 6 then fpd6
                                  when 7 then fpd7
                                  when 8 then fpd8
                                  when 9 then fpd9
                                  when 10 then fpd10
                                  when 11 then fpd11
                                  when 12 then fpd12
                                  when 13 then fpd13
                                  when 14 then fpd14
                                  when 15 then fpd15
                                  when 16 then fpd16
                                  when 17 then fpd17
                                  when 18 then fpd18
                                  when 19 then fpd19
                                  when 20 then fpd20
                                  when 21 then fpd21
                                  when 22 then fpd22
                                  when 23 then fpd23
                                  when 24 then fpd24
                                  when 25 then fpd25
                                  when 26 then fpd26
                                  when 27 then fpd27
                                  when 28 then fpd28
                                  when 29 then fpd29
                                  when 30 then fpd30
                                  when 31 then fpd31
                        else null
                        end as spts
                       ,serial_no
                       ,cedia_code
                 from   x cross join m_low_plan_details
                 where  serial_no = p_serial_no
                 and    cedia_code = p_cedia_code
                 and    low_plan_no = p_low_plan_no
           where  nvl(spts,0) > 0
          ) A
          join m_low_plan_details B on (    A.low_plan_no = B.low_plan_no
                                        and A.cedia_code = B.cedia_code
                                        and A.serial_no = B.serial_no
          join m_low_plan_mstr C on (    B.low_plan_no = C.low_plan_no
                                     and B.client_code = C.client_code
                                     and B.variant_code = C.variant_code
    connect by level <= spts;... so just remind us again why you think it needs to be dynamic?

  • ESQL/C: Difficulties with DECLARE CURSOR  and nested FROM CLAUSE

    Hello @All,
    i am trying to migrate an old esql-c-Application to Oracle 11g (on 64-Bit-AIX 7.1 - Platform)
    PreCompiling is OK, but during runtime the following DECLARE - Statement returns ORA-01001: invalid cursor :
    EXEC SQL
    DECLARE cur_xyz CURSOR FOR
    SELECT vPE, mPE, mZW, COUNT (*)
    FROM ( SELECT v.K_PE AS vPE, m.K_PE AS mPE, m.ZW AS mZW, v.VKG
    FROM ( SELECT K_NR, K_PE, u3.VKG, POS
    FROM u3, r
    WHERE u3.K_NR = '999999'
    AND     u3.LANG = 'F'
    AND SUBSTR (PRTCTRL, 5, 1) > '0'
    AND u3.VKG = r.VKG ( + )
    ) v, m
    WHERE
    v.K_NR = m.K_NR ( + )
    AND v.K_PE = m.K_PE ( + )
    AND POS is Null
    ) X
    WHERE not EXISTS (SELECT VKG FROM NP WHERE X.VKG = NP.VKG )
    GROUP BY vPE, mPE, mZW
    ORDER BY vPE
    When I run this statement without "EXEC SQL DECLARE cur_xyz CURSOR FOR" in SQL-Developer, there is no problem.
    What is my fault? I hope, that I don't have to redesign this.
    Thx in advance for anyonce help.

    Hey Billy,
    I work in a C/C++-Environment under AIX. I allready build a library with with more than x.000 Functions with ESQL-Statements.
    Most of them are running.
    If I need a CURSOR, I allways use constructs like this:
    EXEC SQL DECLARE CursorName [SCROLL]CURSOR FOR
    SELECT ...
    if (SQLC == 0) {
    EXEC SQL OPEN CursorName;
    while (SQLC == 0) {
    EXEC SQL FETCH ... CursorName INTO :<Structure or Fieldlist>;
    EXEC SQL CLOSE CursorName;
    At the Moment, I don't work with a cursor-variable in the DECLARE-Section.
    In the case i discribed above, it is the first, where the ORA-01001 occurs.
    Is it necessary to work with SQL_CURSOR - Variable in all or in special cases?
    Thx 4 answers.

  • Problem with fetch cursor statement

    Hi,
    I am using FETCH CURSOR statement to fetch the data from a database table with package size. For the fetched records I am doing parallel processing using parallel processing frame work in banking system.
    Here the problem is for the first iteration it works fine but when it comes to FETCH NEXT CURSOR in the second iteration , programs gets dumping by saying that 'CURSOR already closed'.
    I am not closing the cursor in the program but some how it got closed some where in the standard function module which I used for parallel processing.
    I used WITHHOLD also along with FETCH CURSOR but no use. Please let me know how to avoid the cursor to get close.
    Below is my code
    IF NOT l_tab_product IS INITIAL.
        OPEN CURSOR WITH HOLD lv_cursor FOR
         SELECT contract_int prodint cn_currency mig_grp
              INTO TABLE gt_cont
                FROM bca_contract
                FOR ALL ENTRIES IN l_tab_product
                WHERE prodint = l_tab_product-prodint
                AND   mig_grp IN s_migrp.
        DO.
          FETCH NEXT CURSOR lv_cursor
                            INTO TABLE gt_cont
                                 PACKAGE SIZE lv_size.
          IF sy-subrc <> 0.
            CLOSE CURSOR lv_cursor.
            EXIT.
          ELSE.
    parallel processing logic
    ENDDO.
    ENDIF.

    Using Withhold will not make sure that the cursor will not get closed because of commits.
    SAP Doc says
    If the addition WITH HOLD is specified, the database cursor is not closed by a database commit executed using Native SQL. The addition does not have an influence, however, on implicit database commits or on any rollbacks which always close the database cursor.
    You have to check the part written in your parallel processing logic.
    As Brad said please donot dump your old threads like this.

Maybe you are looking for

  • Machine will not boot; hard drive makes clicking noise

    My G4 will not boot up. Here are the symptoms: It passed the hardware test; Will not perform a safe start - so cannot run disk utility; Hard drive makes a clicking noise. I'd appreciate any advice about how to proceed. pdh

  • IDOC to File : "no interface found"

    Hi all, I have an IDOC to file scenario and I'm getting the error "no interface found" at sxmb_moni. The scenario is only for test purposes, very simple, using the IDOC /ISDFPS/T01./ISDFPS/T0101. I have configured -> receiver and interface determinat

  • How to check service failover  in RAC system

    Hi experts, We have 4 nodes with oracle 10G2 at redhat. we create some service with failover function. some service is not. total 4 services is in system. I try to use below SQL to find services failover function. == select INST_ID,STATUS, FAILOVER_T

  • Lit up screen draining battery after flash message

    I am using 3GS model. After my last upgrade to 4.3.3 after recieving flash messages my phone's screen lights up again after few seconds, and remains like that. It responds only after pressing home button after that. so if it is at night (during sleep

  • Oracle 10gR2 and jdk 6

    helo... i am new to both oracle and java. i would like to use jdbc in oracle. is it possible if i use oracle 10g database with jdk 6 as a paltform to write a program then load it to oracle using loadjava. or do i need to change my jdk version to 1.4?