tags:

views:

40

answers:

2

I am currently trying to populate a cursor in the procedure.

like that :

Function notImportantFunction
   variable nothing(20);
   Cursor notImportantCursor Is select...;
   Cursor THEcursor;
begin
    open notImportantCursor;
    open THEcursor;
    LOOP
        FETCH notImportantCursor variable;
    EXIT WHEN notImportantCursor%NOTFOUND;
        THEcursor is select ...; //trying to populate THEcursor
    end loop;
    close THEcursor;
    close notImportantCursor;
end;

i've used weird name for my variable just to show the only important one here is THEcursor.

is what i'm trying even possible? or, how would I be able to do the same in another way.

thank you in advance

A: 

I'm not quite sure what you're trying to do - populate a cursor? A cursor is based on a query, so how do you plan to populate that? Maybe you want to populate a table based on a cursor? You can do that by accumulating the cursor results into a collection then using a bulk-insert to populate the table.

FrustratedWithFormsDesigner
hmm, maybe I didnt used the right term. Forget populate. Let say I meant I want to dynamicaly fill the cursor with different values for each iteration of the loop
Zwik
+1  A: 

I think what you are asking for is "Can I create a cursor based on a query that I don't have to define when I declare the cursor" If thats what you want, then look here for information about dynamic sql.

Dynamic SQL

There is a perfect example in the section Referencing Database Objects that Do Not Exist at Compilation. You can recreate the cursor each time, however you want.
If you need something a little more flexible, like creating a cursor that holds three values in each record and you want to populate those values in different ways, you could look for pipelined table functions

moleboy