Invalid cursor within the service in pipeline

The simple example following illustrates a mistake that I am experiencing with development code more complex.

I try to reuse a complex procedure that I do not have duplication of code and business logic.

It runs correctly.

exec PKG_TEST.complex_proc(:p_cursor);

This property returns an error:

exec PKG_TEST.select_rows(:p_cursor);

The error is ORA-01001: Invalid cursor.

I checked and the cursor is opened and % notfound is false.

Any ideas?

Thank you in advance for your help!

create the table employees

(

primary key ID number,

name varchar2 (100)

);

insert into employee values (1, 'Joe');

insert into employee values (2, 'Bob');

insert into employee values (3, 'Peter');

create table contractor

(

primary key ID number,

name varchar2 (100)

);

insert into a values (4, 'Henry') contractor;

insert into contractor values (5, 'William');

create or replace package PKG_TEST

is

type t_rec is rendered

(

Identification number,

name varchar (100)

);

type t_tab is table of the t_rec;

procedure complex_proc (p_cursor to sys_refcursor);

function select_fn (p_cursor sys_refcursor)

return PKG_TEST.t_tab in pipeline;

select_rows (p_cursor to sys_refcursor) procedure;

end pkg_test;

create or replace package PKG_TEST body

is

procedure complex_proc (out p_cursor sys_refcursor)

is

Start

Open the p_cursor for

Select *.

the employee;

end complex_proc;

function select_fn (p_cursor sys_refcursor)

return PKG_TEST.t_tab pipeline

is

v_tab PKG_TEST.t_tab;

v_rec PKG_TEST.t_rec;

Start

loop

collect the fetch p_cursor in bulk in the v_tab limit 100;

because me in 1... v_tab. Count

loop

v_rec: = v_tab (i);

pipe row (v_rec);

end loop;

When the output p_cursor % NOTFOUND;

end loop;

return;

end select_fn;

select_rows (exit p_cursor sys_refcursor) procedure

is

v_cursor sys_refcursor;

Start

PKG_TEST.complex_proc (v_cursor);

Open the p_cursor for

Select *.

table (PKG_TEST.select_fn (v_cursor))

Union of all the

Select *.

contractor;

select_rows end;

end pkg_test;

Problem is that your variable v_cursor in SELECT_ROWS is out of scope when the procedure ends.

So the ref cursor returned by this method cannot be referenced it more.

If you are on 11g and beyond, a workaround is to declare v_cursor DBMS_SQL cursor (for example an INTEGER data type) and use DBMS_SQL.to_cursor_number / DBMS_SQL.to_refcursor to convert between the two.

In this way, the query pointed to by the final Ref cursor will always have a valid binding variable when the procedure ends.

function select_fn( p_cursor in integer )
return PKG_TEST.t_tab pipelined
is

  v_tab         PKG_TEST.t_tab;
  v_rec         PKG_TEST.t_rec;
  v_cursor_num  integer := p_cursor;
  v_cursor      sys_refcursor := dbms_sql.to_refcursor(v_cursor_num);

begin

  loop

    fetch v_cursor bulk collect into v_tab limit 100;

    --exit when p_cursor%NOTFOUND;
    exit when v_tab.count = 0;

     for i in 1 .. v_tab.count
     loop
        v_rec := v_tab(i);
        pipe row(v_rec);
     end loop;

  end loop;

  close v_cursor;

  return;

end select_fn;
procedure select_rows ( p_cursor out sys_refcursor )
is
   v_cursor  sys_refcursor;
   v_cursor2 integer;
begin
   PKG_TEST.complex_proc(v_cursor);

   v_cursor2 := dbms_sql.to_cursor_number(v_cursor);

   open p_cursor for
   select *
   from TABLE(PKG_TEST.select_fn(v_cursor2))
   union all
   select *
   from contractor;

end select_rows;

Tags: Database

Similar Questions

  • How to filter data in cursors within the procedure

    Hello

    Yesterday, I tried all night, but couldn't do it.

    I know that is incomplete, I just want to know how to filter the data based on the setting in

    Basically, here I want to get only the records that match the id_fichier


    create or replace PROCEDURE clearing_details (p_file_id in varchar2)
    IS
    strStatusCode VARCHAR2 (6);
    CURSOR PD1 IS
    SELECT COUNTRY_CODE, EOD_MARK OF LINK_STATUS WHERE FILE_ID is p_file_id


    Can someone help me on this please:


    Thanks for reading.

    Does do the same if you run the query itself in SQL * Plus with the same value you pass as a parameter?

    Without seeing your data and which parameter you're passing, we will fight help more as the concept itself works great as you have been demonstrated.

  • Declare the cursor within the begin/end block

    Hi all
    Can we declare a cursor inside a begin/end block. If we can, please let me know how. I want to declare a cursor where it will return value based on the settings of the user. User will enter in as username(for example), we have to recover the ID, the user name and we must move to cursor. To do this, we wrote a query to fetch id in a variable in the other block of start/end and we pass this variable in the cursor. Is this possible.



    Thank you and best regards,
    Mahesh

    In general, yes you can, you simply nest another block of execution inside of your...

    begin
      declare
        cursor x is select dummy from dual;
      begin
        ...
      end;
    end;
    /
    
  • Purge to open payable Interface ends with the error "Invalid Cursor"

    Hello

    I'm running Purge of open accounts payable (version 115.8) Interface and get an error of invalid cursor in the beforereport trigger. No one knows the cause and the cure for it? Part of the log is below. I looked at the cursor level and everything seems fine for me.

    MSG-00001: Check (Import_purge 1) Panel for the purge process
    MSG-00001: (Check_control_table 1) to lock the table control
    MSG-00003: Fetch (Check_control_table 2) import_requests
    MSG-00004: (Check_control_table 3) check the status of concurrent program
    MSG-00999: FUNCTION GET_REQUEST_STATUS ERROR, Reason:
    MSG-00999: FND_CONCURRENT. GET_REQUEST_STATUS <-Check_control_table <-Import_purge <-pre-writ report <-APXIIPRG
    MSG-00999: check_control_table <-Import_purge <-pre-writ report <-APXIIPRG
    MSG-00999: Check (Import_purge 1) Panel for the purge process
    MSG-00999: delete the record in the command table...
    MSG-00999: ORA-01001: Invalid cursor
    REP-1419: 'beforereport': program abandoned PL/SQL.

    Thank you.

    I'm running Purge of open accounts payable (version 115.8) Interface and get an error of invalid cursor in the beforereport trigger. No one knows the cause and the cure for it? Part of the log is below. I looked at the cursor level and everything seems fine for me.

    MSG-00001: Check (Import_purge 1) Panel for the purge process
    MSG-00001: (Check_control_table 1) to lock the table control
    MSG-00003: Fetch (Check_control_table 2) import_requests
    MSG-00004: (Check_control_table 3) check the status of concurrent program
    MSG-00999: FUNCTION GET_REQUEST_STATUS ERROR, Reason:
    MSG-00999: FND_CONCURRENT. GET_REQUEST_STATUS<><><- before="" report="" trigger=""><->
    MSG-00999: check_control_table<><- before="" report="" trigger=""><->
    MSG-00999: Check (Import_purge 1) Panel for the purge process
    MSG-00999: delete the record in the command table...
    MSG-00999: ORA-01001: Invalid cursor
    REP-1419: 'beforereport': program abandoned PL/SQL.

    11i: debt open Interface import bill (APXIIMPT) [ID 107628.1] Troubleshooting Guide - 3. Open the Purge Import Interface fails with ORA-01001: Invalid cursor

    Thank you
    Hussein

  • Firefox is a cursor in the window html pages that can be changed to spoil the option to scroll using the arrow keys

    Whenever I click in a window to scroll through my arrows is put a cursor in the window and scrolling out of it, instead of scrolling the entire page using the arrow key it scrolls by the location of the cursor within the window as a word document.

    Press F7 to disable the keyboard navigation.

    http://KB.mozillazine.org/accessibility.browsewithcaret

  • Execution of the query against the service

    I wonder what's the difference between running a query on a region that partitioned for a set of objects cached vs using a function distributed to the combined results and return them to the node running?

    The problem, I'm trying make me get all objects from the cache in a region that partitioned a certain type and then perform a calculation on the subject after I he gains the cache to see if it should be added to all final results that I return to my request. I'm not aiming for a specific node for these objects; they can reside anywhere in the partitioned area. Is this the same difference using a query and running the calculation on each object in the result of the query defined in terms of running a distributed function and perform the calculation in distributed mode before returning the results to the running node?

    I think I would use the API to query within the service (Query.execute (RegionFunctionContext)) to query local entries. Are you familiar with the API Query.execute (RegionFunctionContext)? Basically, who runs the query only on local data.

    Then filter these additional results in the function, and then finally to return results filtered out to the customer. Do the same filtering on each local server before returning anything to the client. According to the difference between the result set size and size final filtered results, you will gain a lot of IO, not to mention the serialization/deserialization. You may also be able to do the calculation in the query itself if you have a method for this in the object.

    Barry

  • ESX 3.5: copy files using the service console from a network share to the esx host data store

    Hello

    I wonder. Is there a command that I can run the service console that would allow me to copy a file from a network share on the data store on the esx host?

    Eric

    If sharing is a Windows, you can also use smbclient within the service console and ride sharing.

    André

    * If you found this device or any other answer useful please consider awarding points for correct or helpful answers

  • Cursor inside the DBMS_XMLGen.newContext SetRowTag?

    Hello

    I have the following code
    v_ctx := DBMS_XMLGen.newContext('select ' || chr(39) || 'F5' || chr(39) || ' as "sender",
                                            payloadid as "messageId",
                                            ordernumber as "orderNumber", 
                                            recordtype as "recordType", 
                                            billtoid as "billToId", 
                                            shiptoid as "shipToId", 
                                            shipperid as "shipperId", 
                                            shipfromid as "shipFromId", 
                                            currency as "currency", 
                                            siteid as "siteId", 
                                            carrierid as "carrierId", 
                                            forwarderid as "forwarderId",
                                            flexcharacterattr7 as "flexCharacterAttr7",
                             hazardousindicator as "hazardousIndicator",
                                            motcode as "motCode",
                                            enduserid as "endUserId",
                                            orderdate as "orderDate",
                                            paymentterm as "paymentTerm",
                                            routedexportindicator as "routedExportIndicator", 
                                            cursor(select linenumber as "lineNumber"
                                                     from f5_ec_order_ln_out b
                                                    where b.ordernumber = a.ordernumber) "lineRequest"  
                                       from f5_ec_order_hdr_out a
                                      where payloadid = 15');
    
    DBMS_XMLGen.setRowsetTag(v_ctx, 'orderRequest');
    DBMS_XMLGen.setRowTag(v_ctx, 'headerRequest');
    It's return of lines with a tag line
    <lineRequest>
    <lineRequest_ROW>
    <lineNumber>1078</lineNumber>
    </lineRequest_ROW>
    <lineRequest_ROW>
    <lineNumber>1079</lineNumber>
    Y at - it some sort of command as

    DBMS_XMLGen.setRowTag (v_ctx, 'headerRequest');

    is there a slider inside this declaration as routines such as

    DBMS_XMLGen.setRowsetTag (v_ctx, 'orderRequest');
    DBMS_XMLGen.setRowTag (v_ctx, 'headerRequest');

    for the cursor within the party or I have to use a replacement on my XML just after?

    Thanks in advance!

    You can use xmlagg places the internal cursor:

    SQL> declare
      2   v_ctx dbms_xmlgen.ctxHandle;
      3   x varchar2(2000);
      4  begin
      5    v_ctx := DBMS_XMLGen.newContext('select dname ,
      6                                            (select xmlagg(xmlelement("lineNumber",ename))
      7                                                   from emp b
      8                                                  where b.deptno = a.deptno) "lineRequest"
      9                                     from dept a');
     10
     11    DBMS_XMLGen.setRowsetTag(v_ctx, 'orderRequest');
     12    DBMS_XMLGen.setRowTag(v_ctx, 'headerRequest');
     13    x := dbms_xmlgen.getxml(v_ctx);
     14    dbms_output.put_line(x);
     15  end;
     16  /
    
    
     
    
    ACCOUNTING
      
    
    CLARKKINGMILLER  
     
     
    
    RESEARCH
      
    
    SMITHJONESSCOTTADAMSFORD
    
     
     
      SALES
    
    
    
    ALLENWARDMARTINBLAKETURNERJAMES  
     
     
    
    OPERATIONS
     
    
    
    PL/SQL procedure successfully completed.
    

    Max
    http://oracleitalia.WordPress.com

  • Error in windows 2003 Standard Edition with Service Pack 2... The server {00024500-0000-0000-C000-000000000046} is not registered with DCOM within the required time.

    Could someone fix for the error below...

    OS: Windows 2003 Standard Edition with Service Pack 2...

    Event type: error
    Event Source: DCOM
    Event category: no
    Event ID: 10010
    Date: 08/08/2012
    Time: 10:00:31
    User: n/a
    Computer: BP1WHIAP011
    Description:
    The server {00024500-0000-0000-C000-000000000046} is not registered with DCOM within the required time.

    Hello
    For assistance on this issue, you can post your question in the Technet Forums.
    http://social.technet.Microsoft.com/forums/en-us/categories/

  • Error 6 - the handle is invalid when you try to start the services.

    Error 6 - the handle is invalid

    HII
    I really need help
    If you sat down me - it would be great.
    in my organzition - 5 different computers - all THE of THEM with the HELP of Win Xp Sp3
     
    started having error - error 6 - the handle is invalid
    When we want to start very imporatnt services
    print spooler
    the Windows Installer
    EXC
    When we try to start these service - we get the error - thT THE HANDLE IS INVALID - ERROR 6
    and the service - was able to start

    10 x in advance

    Thank you very much
    We have made the controls more
    is it was the fault of the Anti Virus
    We always face the problem - but we know who is to blame
    We use the endpoint of Symantec Enterprise solution
    When we disabled anti virus service - other services began to operate properly

    We contacted Symantec support to see if they have a solution to the problem
    really 10 X

  • Service Acquisition of Image Windows (WIA) suspended at startup. Responding server {81ED811 A1F4E726-8CF1 - 11 d 1-BF92-00600} is not registered with DCOM within the required time.

    Since early April 2010, my computer started to shut down immediately after starting, or at a time later. A lot of system errors and other events have been reported in the error log, which much of this: "the MMTP service failed to start due to the error - the following system could not find the specified file - after 31/2 months, I abandoned this fixation and F11 to restart or reload the system to the original system; Have updated and 135 items updated, installed IE8, WinXP Pro + SP3 and finally my HP Laser Jet printer 5 p. Try to strt the computer a few hours later, but it stops immediately after, within 2-3 seconds; Repeat this several times. Unplugged the printer, the computer began; The error showd 2 journal items, repeated several times. i.e.

    (1) the service Acquisition of Image Windows (WIA) suspended at startup.                                                  (2) the server {81ED811 A1F4E726-8CF1 - 11 D 1-BF92-00600} is not registered with DCOM ala required timeout.  Can someone help please? I have to go into msconfig and other? I'm tired & patience thereby and the help that I received from the MS Tech Support.

    Help, please! Thank you! HeinrichDS

    Thanks "nass 1" for your support, I will follow Palouk recommendations to update the drivers for the HP product and hope it will be OK.

    I appreciate your help, HeinrichDS

    HeinrichDS

  • OVD Custom Plugin - return invalid authentication to the Proxy Service

    Hi all

    I develop a plugin for OVD. My goal is to call a Service Proxy by using the credentials of a user in TPM. However, in this plugin, I'm calling a Web service and the authentication result depends on the result of this Webservice. For example, if the WS returns 'false', this means that I should not be allowed to authenticate.

    How can I find an invalid authentication at the request of Service of Proxy, using my plugin implementation?

    Thank you very much.

    You can use the bind method:

    BasePlugin (reference APIs Java Oracle Virtual Directory)

    and set it as the

    ' Public Sub bind (String, String, credentials creds, dn DirectoryString,

    BinarySyntax password, Boolean result) throws DirectoryException.

    {ChainException}

    try {}

    Boolean auth is xyz. Auth (uidValue, pwdValue);

    bool.setValue (auth);

    } catch (Exception e) {}

    Logger.info ("exception:" + e.getMessage (), e);

    bool.setValue (false);

    Customization of Oracle Virtual Directory - 11g Release 1 (11.1.1)

    ~ J

  • Initialize the Ref Cursor to avoid ORA-01001: Invalid cursor

    Hello

    I write a stored procedure that returns a REF CURSOR. However, there are times when the cursor is not open if certain conditions are not met, so I wonder if there is a way to initialize the REF CURSOR so that the appellant does not receive the "ORA-01001: Invalid cursor" error when you try to work with the cursor, if it has not been opened.

    Any help is greatly appreciated...

    Thank you
    Christine

    cad0227 wrote:
    Hello

    I write a stored procedure that returns a REF CURSOR. However, there are times when the cursor is not open if certain conditions are not met, so I wonder if there is a way to initialize the REF CURSOR so that the appellant does not receive the "ORA-01001: Invalid cursor" error when you try to work with the cursor, if it has not been opened.

    Any help is greatly appreciated...

    Thank you
    Christine

    The most appropriate way would be the caller to handle the situation. The caller must capture the exception of INVALID_CURSOR and do what is necessary.

    Other suggestions like having a separate Pavilion or a model select all will lead the appellant to act to the particular situation, that slider is not being opened. What is the case with the exception of INVALID_CURSOR raised by oracle.

    All the need for the appellant to do is manage the exception of INVALID_CURSOR and you should be good. And also INVALID_CURSOR is not a mistake, it's an exception that has a special meaning for her. In the case you sense it takes the condition when not together to return a cursor.

  • INVALID CURSOR - block anonymous component the cursor in function

    I get an error when you try to call my cursor.
    CREATE OR REPLACE PACKAGE tax_update
    AS
     TYPE gencur IS ref cursor;
     FUNCTION tax_sf
     (
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
     )
     RETURN NUMBER;
    END;
    / 
    CREATE OR REPLACE PACKAGE BODY tax_update
    AS
     FUNCTION tax_sf
     (
       p_state IN bb_tax.state%type,
       p_thecursor IN OUT gencur
     )
     RETURN NUMBER
      IS
      lv_taxrate NUMBER;
     BEGIN
      OPEN p_thecursor FOR 
       SELECT taxrate 
       FROM bb_tax
       WHERE state = p_state;
      RETURN lv_taxrate;
     END;
    END;
    / 
    DECLARE
      tax_cur tax_update.gencur;
      rec_tax bb_tax%rowtype;
     BEGIN
     LOOP
      FETCH tax_cur INTO rec_tax;
       EXIT WHEN tax_cur%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
     END LOOP;
    END;
    DECLARE
    *
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at line 6
    Mission is to create a package that will contain the rate of taxation by the State in a packed slider. The package contains a function that can receive a State of 2 character abbreviated as an argument and finds a match in the cursor and return the tax rates for tha tstate. An anonymous block will test the function with the State of North Carolina.
    If anyone can help?

    user13842802 wrote:
    Have tried a few ways to call but always error on TAX_SF.

    SET SERVEROUTPUT ON
    DECLARE
        tax_cur tax_update.gencur;
        rec_tax bb_tax%rowtype;
    BEGIN
        tax_cur := tax_update.tax_sf('NC');
        LOOP
          FETCH tax_cur INTO rec_tax;
          EXIT WHEN tax_cur%NOTFOUND;
          DBMS_OUTPUT.PUT_LINE(rec_tax.taxrate);
        END LOOP;
    END;
    /
    

    SY.

  • How to detect if the cursor is no longer within the input text area

    Hello.

    My question today is:

    How to detect (in AS3) if the cursor is no longer within the input text area?

    I tried to mouse events, events, events in text but without success.

    Any ideas?

    Concerning

    If you have a textfield of entry with the instance name it '...

    it.addEventListener (FocusEvent.FOCUS_OUT, focusOutHandler);

    function focusOutHandler(evt:FocusEvent):void {}
    trace (evt. Target.Name);
    }

Maybe you are looking for

  • Power 2 Go

    I used Power 2 Go to copy photos on CD - R discs.  After a couple of discs, the writing process stopped at 34% and the program and the computer locked up. I could not close the program, restart the computer, or remove the CD. I had to turn off the PC

  • Upgrading processor... I know, please bear with me

    This is a redundant question, I know and I'm sorry, but I want to be absolutely certain before I give up my search for the upgrade. I have a HP Pavilion DV6-6c35dx with a processor AMD A8 - 3520M. I tried to do things that apparently require an Intel

  • My "Delete" key on the keyboard is deleting is no longer.

    The "DELETE" key on my keyboard does not work.I use the 'remove' frequently when you type, so it makes life difficult. I first noticed that early this am. I thought that a reboot it will probably open upwards. When I turned on computer back this afte

  • How to restore the weather gadget

    original title: I accidently deleted the time gadeget in the sidebar.  When I went to retrieve gadget page, he was not there.  Now what? I accidentally deleted the time gadeget in the sidebar.  When I went to retrieve gadget page, he was not there. 

  • Windows Explorer, some blue, black color display files.

    I have about 20 videos on my HDD, why are two appear blue? I'm not having any problem with the files I just want to know why, (NOTE; I have a C and a D hard drive. What's happened since I dragged these two files on the D drive, where they were copied