Executing multiple queries stored in multiple rows

Hi, 
I have a question. I have a table that contains import scripts for my database. Below is the set up
ID Table
Date Script
1 TableA
NULL INSERT INTO [dbo].[TableA] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
2 TableB
NULL INSERT INTO [dbo].[TableB] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
3 TableC
NULL INSERT INTO [dbo].[TableC] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
4 TableD
NULL INSERT INTO [dbo].[TableD] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
5 TableE
5/28/2013 INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
6 TableE
5/29/2013 INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
7 TableE
5/30/2013 INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
8 TableE
5/31/2013 INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
9 TableE
6/3/2013 INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
10 TableE
6/4/2013 INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
11 TableF
NULL INSERT INTO [dbo].[TableF] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
12 TableF
NULL INSERT INTO [dbo].[TableF] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
13 TableF
NULL INSERT INTO [dbo].[TableF] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
14 TableF
NULL INSERT INTO [dbo].[TableF] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'…
I wrote 4 queries to execute the scripts for table A to D as following:
DECLARE @A varchar(500)
SET @A = (SELECT Script FROM TABLE WHERE [Table] = 'TABLE A')
EXECUTE (@A)
DECLARE @B varchar(500)
SET @B = (SELECT Script FROM TABLE WHERE [Table] = 'TABLE B')
EXECUTE (@B)
DECLARE @C varchar(500)
SET @C = (SELECT Script FROM TABLE WHERE [Table] = 'TABLE C')
EXECUTE (@C)
DECLARE @D varchar(500)
SET @D = (SELECT Script FROM TABLE WHERE [Table] = 'TABLE D')
EXECUTE (@D)
Now I also wish to execute the script from Table E, but only for the Month of May so I decided to write this query
DECLARE @E varchar(500)
SET @E = (SELECT Script FROM TABLE WHERE [Table] = 'TABLE E' AND [Date] BETWEEN '2013-05-01' AND '2013-05-31)
EXECUTE (@E)
I guess this query can't execute because my statement selects more than one script. Now I have data going back to two years and I don't want to write close to 700 statements. Is there a way around it?
Thank you very much in advance!
Cheers

I guess this query can't execute because my statement selects more than one script. Now I have data going back to two years and I don't want to write close to 700 statements. Is there a way around it?
what do you mean by "my statement select more that one script" ?
why do you want to exec all select statement separately ?
you can combine select statement with UNION ALL,
and do you want to specify the date range dynamically , first you specified may and two year is there related to data
Well, if ever i would write 
SELECT Script FROM TABLE WHERE [Table] = 'TABLE E' AND [Date] BETWEEN '2013-05-01' AND '2013-05-31'
I would get this as an answer
INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'… Script for 5/28/2013
INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'… Script for 5/29/2013
INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'… Script for 5/30/2013
INSERT INTO [dbo].[TableE] SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0'… Script for 5/31/2013
Now I want to dynamicaly be able to execute multiple scripts based on a where function. I could also write something saying
WHERE [Table] = 'TABLE E' AND [Date] BETWEEN '2010-01-01' AND GETDATE()
In any case, I would need it to first execute script for 5/28/2013, then script for 5/29/2013, etc..
Thank you in advance,
Cheers

Similar Messages

  • How to execute multiple queries in one stored procedure.

    Hi,
    I am Kumar,
    How to execute multiple queries in one stored procedure.
    here is the my requirements,
    1. get the max value from one table and sum of the that value.
    2. insert the values and also sum of the max value.
    using stored procedure
    I am using SQL server 2000 database.
    Please help me.
    Advance thanks
    by,
    Kumar

    This is not a java question and it is not even a problem: your only problem is
    1) lack of knowledge
    2) lack of interest to find a manual
    But you are going to have to change both by actually reading a book or a manual that explains the stored procedure language of SQL Server. It is the same as Sybase I think, so you could also look for a manual for that DBMS.

  • [Forum FAQ] How do I send multiple rows returned by Execute SQL Task as Email content in SQL Server Integration Services?

    Question:
    There is a scenario that users want to send multiple rows returned by Execute SQL Task as Email content to send to someone. With Execute SQL Task, the Full result set is used when the query returns multiple rows, it must map to a variable of the Object data
    type, then the return result is a rowset object, so we cannot directly send the result variable as Email content. Is there a way that we can extract the table row values that are stored in the Object variable as Email content to send to someone?
    Answer:
    To achieve this requirement, we can use a Foreach Loop container to extract the table row values that are stored in the Object variable into package variables, then use a Script Task to write the data stored in packages variables to a variable, and then set
    the variable as MessageSource in the Send Mail Task. 
    Add four variables in the package as below:
    Double-click the Execute SQL Task to open the Execute SQL Task Editor, then change the ResultSet property to “Full result set”. Assuming that the SQL Statement like below:
    SELECT   Category, CntRecords
    FROM         [table_name]
    In the Result Set pane, add a result like below (please note that we must use 0 as the result set name when the result set type is Full result set):
    Drag a Foreach Loop Container connects to the Execute SQL Task. 
    Double-click the Foreach Loop Container to open the Foreach Loop Editor, in the Collection tab, change the Enumerator to Foreach ADO Enumerator, then select User:result as ADO object source variable.
    Click the Variable Mappings pane, add two Variables as below:
    Drag a Script Task within the Foreach Loop Container.
    The C# code that can be used only in SSIS 2008 and above in Script Task as below:
    public void Main()
       // TODO: Add your code here
                Variables varCollection = null;
                string message = string.Empty;
                Dts.VariableDispenser.LockForWrite("User::Message");
                Dts.VariableDispenser.LockForWrite("User::Category");
                Dts.VariableDispenser.LockForWrite("User::CntRecords");     
                Dts.VariableDispenser.GetVariables(ref varCollection);
                //Format the query result with tab delimiters
                message = string.Format("{0}\t{1}\n",
                                            varCollection["User::Category"].Value,
                                            varCollection["User::CntRecords"].Value
               varCollection["User::Message"].Value = varCollection["User::Message"].Value + message;   
               Dts.TaskResult = (int)ScriptResults.Success;
    The VB code that can be used only in SSIS 2005 and above in Script Task as below, please note that in SSIS 2005, we should
    change PrecompileScriptIntoBinaryCode property to False and Run64BitRuntime property to False
    Public Sub Main()
            ' Add your code here
            Dim varCollection As Variables = Nothing
            Dim message As String = String.Empty
            Dts.VariableDispenser.LockForWrite("User::Message")
            Dts.VariableDispenser.LockForWrite("User::Category")
            Dts.VariableDispenser.LockForWrite("User::CntRecords")
            Dts.VariableDispenser.GetVariables(varCollection)
            'Format the query result with tab delimiters
            message = String.Format("{0}" & vbTab & "{1}" & vbLf, varCollection("User::Category").Value, varCollection("User::CntRecords").Value)
            varCollection("User::Message").Value = DirectCast(varCollection("User::Message").Value,String) + message
            Dts.TaskResult = ScriptResults.Success
    End Sub
    Drag Send Mail Task to Control Flow pane and connect it to Foreach Loop Container.
    Double-click the Send Mail Task to specify the appropriate settings, then in the Expressions tab, use the Message variable as the MessageSource Property as below:
    The final design surface like below:
    References:
    Result Sets in the Execute SQL Task
    Applies to:
    Integration Services 2005
    Integration Services 2008
    Integration Services 2008 R2
    Integration Services 2012
    Integration Services 2014
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • Retreiving multiple rows with stored procedures

    Hi,
    I'm having a little problem over here. I need to retreive some data (from an oracle db) via stored procedures. But I don't know how I can retreive multiple rows because when I execute a stored procedure which gives more dan 1 row back, Jave throws an exception.
    If someone could show me an example (or url) from how it should be done, it will be very much appreciated :-)
    Thanks in advance.

    A collection of (mostly) fully working example programs is provided by Oracle.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
    I think what you're looking for it the RefCursor example, under "JDBC Basic Samples"

  • Retruring Multiple rows from a Stored Procedure

    The Oracle JDBC documentation shows how to return a cursor pointer through the parameter list of a stored procedure allowing a Java program to use the cursor like a normal result set. I've tried it (using the thin driver) and it works fine - however, I'm having trouble getting this to work running the program under a Weblogic server (using their own JDBC implementation). So, I have two questions:
    1) Has anyone had this problem before and solved it ??
    2) Are there any other techniques for getting multiple rows back from the database without having to fire "raw" sql at it ?

    Hi
    You could return not resultset but array, for example:
    PACKAGE TEST:
    type string_table is table of varchar2(80)
    index by binary_integer;
    function get_something (
    something1 out string_table,
    arraylength in number
    ) return number;
    PACKAGE'S BODY:
    function get_something (
    something1 out string_table,
    arraylength in number /** length of the array **/
    ) return number as
    cursor C is
    select something1, ...
    from test_table;
    pos number := 1;
    begin
    for position in C loop
    exit when (pos > arraylength);
    something1(pos) := position.something1;
    pos := pos + 1;
    end loop;
    return (pos - 1);
    end;
    Of course in this example you need to know length of your array
    (arraylength parameter), but you can avoid such problem, for
    example, by using DBMS_SQL package (or dynamic SQL feature in
    the Oracle8i).
    Andrew
    Mladen Gogala (guest) wrote:
    : Phil Hildebrand (guest) wrote:
    : : Is there a way that I can return multiple rows from a stored
    : : procedure for function ?
    : : Something like:
    : : CREATE FUNCTION sp_get_children (my_nip IN port.nip_num%
    TYPE)
    : : RETURN my_nip
    : : IS
    : : CURSOR child_cur IS
    : : SELECT nip_num
    : : FROM logical_port
    : : WHERE port_num = my_nip;
    : : child_rec child_cur%rowtype;
    : : BEGIN
    : : FOR child_rec IN child_cur
    : : LOOP
    : : RETURN my_nip;
    : : END LOOP;
    : : END tmp_sp_get_children;
    : : I know how to do it in Informix ( RETURN WITH RESUME ), but
    : I'm
    : : not running Informix ;)
    : : Thanks,
    : : Phil
    : In contrast with Informix, SQL Server and Sybase, Oracle
    : can not return a result set. the only workaround is to
    : return the cursor variable as such.
    null

  • SQL Developer cannot execute multiple queries in one connection

    Hi,
    Using : SQL Developer 1.2.29.98, Oracle Database 9i on Windows XP.
    Currently I have TOAD and PL/SQL Developer to handle things related to Oracle Database.
    I found this SQL Developer tools as an interesting tool which might replace PL/SQL Developer (I assume).
    I opened two SQL Worksheets and tried to execute 2 queries (time consuming one) simultanously, suddenly it freezes (the window become grayed). Just like TOAD, we cannot smoothly execute multiple queries on single connection on SQL Developer
    I can monitor the query process using TOAD (Session Browser) and found both queries are running while SQL Developer window become grayed and seems not functioning. After the queries have been finished, I mean both of them, the SQL Developer window become normal and "alive" again showing the expected results.
    Well, however PL/SQL Developer could handle this. Executing multiple queries in single application is just its unbeatable features.
    We can view the query result once its finished instead of until the others being processed, by just only switch the SQL Windows.
    Is it true that SQL Developer doesn't support executing multiple queries?
    Or is it a feature which we should request?
    Or we have to activate this feature by doing some changes on configuration / preferences?
    (Do we need to open two SQL Developer instances? what a memory consuming solution).
    Regards,
    Buntoro

    SQLDeveloper connections are single threaded and also rather single minded (in that you can't do much else while a long query is running.)
    There is an existing feature request http://apex.oracle.com/pls/otn/f?p=42626:39:3685254426061901::NO::P39_ID:4202 for which you can vote.
    The workaround is to have multiple connections. Not brilliant but it works.

  • Execute multiple sql queries in plsql

    Hello All,
    I have two queries, How to execute multiple sql queries in plsql. Once the query completed in sql+ that report/output has to come in html.
    Please guide to how to do that.
    Thanks and Regards,
    Muthu
    [email protected]

    There are several ways to do what you are wanting, but you should consider posting your question in the correct forum (PL/SQL). This forum is for question about Oracle Forms! :)
    As to your question, take a look at this: How to output query results as HTML.
    Craig...

  • Inserting multiple rows into DB via SQL insert or stored procedure?

    I have successfully created an application where I select a row in an output table view from a Microsoft Access DB SQL data source, and get an Oracle stored procedure to save the row in a new table in our Oracle DB.
    This works like a charm when selecting one single row in the table view. What I really need though is for the procedure to save multiple rows at once.
    My table is configured with selection mode = 'multiple', and the data mapping line between the table and my procedure has mapping scope = 'selected data rows'.
    So, I am able to select multiple rows but still my procedure only stores one of the values sent. Does anyone know if this is related to my procedure not handling multiple parameter entries or if it's related to how VC outputs data to a procedure?
    Here is output from runtime flex log where you see the three values: 3, 11 and 9 that is sent to the procedure's IN parameter 'P_ID'.
    <Row OWNAPPS_TESTSQL_HYTTER_P_ID="3"/><Row OWNAPPS_TESTSQL_HYTTER_P_ID="11"/><Row OWNAPPS_TESTSQL_HYTTER_P_ID="9"/>
    Please help
    Henning Strand
    I am still very, very interested in hearing if anyone has been successful at passing multiple rows to a stored procedure in one submit action.
    Edited by: Henning Strand on Apr 11, 2008 1:58 PM

    Update for all you happy people using Oracle stored procedures with Visual Composer:
    When trying to run a simple procedure that accepts arrays as input parameters, the JDBC connector returns an error message saying: 'PLS-00306: wrong number or types of arguments in call ...'
    I registered this as a customer message with sap support and got an answer back saying:
    Unfotunately our JDBC connector is still not able to work with SP that contain arrays, this is the reason for the behaviour that you're seeing.
    This are the bad news, the good news is that with WebServices we don't have this limitation, so you can achieve the same results by using a WS instead of the Store Procedure.
    I have asked if and when using stored procedures with arrays will be supported - waiting for answer.
    Henning Strand

  • Execute Multiple Queries on Screen Load: ADF Swings

    how can i execute multiple queries and populate each query value to corresponding combo box .assume i what to execute 5 different query and populate it into 5 different combo box.
    Prakash

    Hi,
    if you work with ADF then all iterators are accessible through the panelBinding object
    DCIteratorBinding dciter = (DCIteratorBinding) panelBinding.get("Iterator Name");
    dciter.execute();
    If you need to add query parameters like bind parameters then a call to the execute with params method (if available in the binding) could be perfomed as an OperationBinding
    OperatioNBinding oper= (OperatioNBinding ) panelBinding.get("ExecuteWithParams");
    oper.getParamMap().put("bind variable name", <value>);
    oper.execute();
    Frank

  • Stored Procedure Returning Multiple Rows

    Hello. Where can I find sample code from a class that calls a stored procedure that returns multiple rows?
    I have a servlet that calls the DB directly from the servlet & loops through the result set. I want to put that code into a stored procedure, but I'm not sure how to loop through the results.
    Your help is greatly appreciated!

    Surely you would call the stored procedure and loop
    through the resultset as usual.
    all that is different is the method by which you obtain the resultSet .
    assuming CallableStatement, Connection have been
    instantiated.
    cstmt=con.prepareCall("{call sp_NewOfficeSurgery (?,?)}");
    cstmt.setString(1,"first");
    cstmt.setString(2,"second");
    rs = cstmt.executeQuery();
    while (rs.next())
    String nme = rs.getString(1)
    etc,etc
    Hope this helps , Sorry If I have misinterpreted this
    please let me know if my thinking is floored or you need
    further clarification ect.
    [email protected]

  • Formula to calculate SUM of multiple sheets of excel and the result to be stored in another excel sheet and pop up alerts for multiple rows

    I have a excel with multiple
         sheets with data as shown below
    SHEET 1
    A 1
    B 2
    C 3
    SHEET 2
    B 1
    C 2
    A 3
    SHEET 3
    C 1
    A 2
    B 3
    My
    query is splitted into 3 categories
    I want to have a formula to do math calculation such that data of "A" of SHEET 1 is  calculated with "A" of SHEET2 irrespective of the location of "A".
    When I include SHEET3, the formula should automatically identify the location of "A" or "B" or "C" and give the result corresponding to A, B or C. Since I want to bifurcate daily report and output printed. I want to use another
    excel for output. How to link multiple sheets of one excel and print the output of above in
         another excel?
    Assume, I have 4 SHEETS,  "SHEET 1", "SHEET 2", "SHEET 3" and "SHEET 4". Math calculation need to be done using all 4 sheets. If
    I include "SHEET 5", the formula should ignore SHEET 1  automatically and give the results of SHEETS 2 to 5. Similarly, if I include SHEET 6, SHEET 1 and 2 need to be ignored for further calculation and SHEET 3-6 need to be used. How to write
    such formula?
    How to get pop up alert for multiple rows, if a specific condition is hit?

    Maybe VBA Code should be a good option for you. I suggest you post you issue to
    Excel for Developers forum.
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us.
    Thanks for your understanding.
    Best Regards,
    Wind

  • Return Code - Query for Multiple Rows as XML

    Hi,
    I'm executing an MSSQL stored procedure through the "Query for Multiple Rows as XML" activity in LiveCycle ES. I do this through a call statement such as this:
    { call MyStoredProc(?) }
    This works great, the stored procedure always returns a record set (with or without records). I use this activity rather than "Call Stored Procedure" because I can transform the record set into XML right away within this activity. Unfortunately any exception arising from invoking this stored procedure cannot be handled within the workflow as this activity does not have an exception handler (lightning bolt). In an attempt to handle at least some exceptions we have decided to use try/catches within the stored procedures and return different error codes. Now the problem I am faced with is that there is no way to retrieve the returned code within any of the SQL activities. We don't want to have to write an execute script for each of these SQL calls. Is there any way to do this? Seems like I'm 95% there.
    Thanks
    Nic

    Thanks for the offer, unfortunately we would need something certified by Adobe.
    Nic

  • INSERT or UPDATE with multiple rows

    Hi there!
    I want to ask what I should do in the following case: I have to handle mutliple rows of data to insert OR to update into the database.
    The first question is about how to decide whether I should take INSERT or UPDATE. I read here in the forum that I could take a SELECT-statement before, and, if it isn't null, I could update the resultset..if it is null I can make an INSERT-statement.
    But now I a have multiple rows to update or to insert which I want to handle as a transaction (with a batch), so I don't want to check each row the way I described above. Does anyone has a hint ?
    Thanks a lot in advance.

    This is not a problem with java but rather a problem
    with databases in general. The solution generally
    depends on the data that is being operated on.
    If there is a primary key involved, and most records
    were expected to NOT be in the database, then you
    could just insert them in blocks (transaction/batch).
    Each block would fail when a primary key duplicate.
    Then you can process each block as individual
    l statements. The ones that fail are done as
    inserts.
    The reverse of the above is used if you expect most
    records to be in the database. Do updates and the
    break out the blocks with failures to locate the
    inserts.
    Keep in mind that queries for keys probably will be
    faster, but that requires that your keys are ordered.
    If you keys are ordered then you can get a range from
    the initial data. Use that to query the database for
    keys between that range (only return the keys.)
    Using the returned keys you can decide whether each
    h record needs to be an update or insert (presort the
    data into each group and batch each group for more
    speed.)
    If the data is really mixed and the database supports
    it then you can write a stored proc (MySQL does not)
    which decides whether an insert/update is needed.
    Finally if you have large amounts of data, bulk
    operations especially inserts are better done with
    tools supplied by the database vendor. Instead of
    using JDBC to do the insert/updates you write the
    output to a file and pass the file to the tool. You
    might use JDBC (again with the ordered key query) to
    decide which operation to do. Although faster for
    large sets this is problematic due to the error
    handling that you have to add.
    Thanks for this, jschell. I look for your answers, because they're on the money and written well. I learn a lot from them. - MOD

  • RFC XI JDBC to external database.... Get data in multiple rows

    Hi,
    We have been really struggling with this scenario. We have created a RFC that has 1 Import parameter (Order_ID) and table parameter (3 Columns: Order_ID, Partner_type, Partner_no).
    When we call this RFC in SAP, it should make a connection to external database via JDBC and get multiple row data for every Order_ID. We are not using Oracle Stored Procedure, instead we are using simple Select statement. Did all the mapping and configured correctly. However, we are getting short-dump when we execute RFC. When we checked in XI, it says " Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at "
    Has anyone tried getting multiple row information from external database(Oracle) using Select statement in XI ? IF so, can you pl let us know if we need to something different in Mapping ?
    Niranjan

    Niranjan,
    Check this blog of mine to see how the datatype for Synchronous Select should be constructed,
    https://weblogs.sdn.sap.com/pub/wlg/3928. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
    If this looks good, a few checks
    1. Check the request inbound payload , i.e the RFC request in MONI. Is this as expected?
    2. Check the output of the request mapping and check if this is as expected.
    3. Check the response from JDBC, is this as per the datatype defined.
    4. Check the mapping from JDBC response to RFC response.
    To me this looks like an issue with the JDBC response structure.
    Meanwhile to understand how to test mapping, check blog of michal,
    /people/michal.krawczyk2/blog/2005/09/16/xi-how-to-test-your-mapping-in-real-life-scenarios
    Regards
    Bhavesh

  • How to execute multiple sql statements in oracle?

    I want to execute multiple statements in a single transaction in oracle. Following are my queries:
    Create table temp_table as Select * from table;
    SELECT * FROM temp_table d;
    drop table temp_table ;
    I am using sql comment text in asp.net
    I am using executenonquery command in asp.net.
    Thanks,
    Divya

    SigCle ,
    Here's an example that executes 3 statements;
    begin insert into foo values(1); insert into foo values(2); insert into foo values(3); end;
    923354,
    The block doesn't compile because temp_table doesn't exist at the point you're trying to compile the anonymous block. I'd recommend re-reading the doc link and forum link provided to get a better understanding of how temp tables work, as it's simply different with Oracle. You don't create Oracle temporary tables on the fly; you create them ahead of time and then just use them. The data itself is already specific to a particular session; you don't create and drop the table each time.
    Also, you can't just "select * from table" in plsql. The results have to GO SOMEWHERE. Usually you'd either open a cursor and process it in the block, or send out a ref cursor if you want to send the data to a client side app. The ref cursor data wouldn't actually be fetched until the block completes though, so you'd need to use ON COMMIT PRESERVE ROWS, which would also mean you'd need to clean up the data yourself (delete the data from the table when you're done with it).
    Corrections/comments welcome.
    Greg

Maybe you are looking for