Cursor in another cursor. how?

i have a program like this
DECLARE
V_VARIABLE1 VARCHAR2(10);
CURSOR_ABC IS select...............;
BEGIN
OPEN CURSOR_ABC;
LOOP
FETCH CURSOR_ABC INTO V_VARIABLE1;
EXIT WHEN CURSOR_ABC%NOTFOUND;
WHAT IF I WANT TO INSERT ANOTHER SAME KINDA CURSOR LOOP HERE LIKE*
CURSOR_XYZ IS select...............;
BEGIN
OPEN CURSOR_XYZ;
LOOP
FETCH CURSOR_XYZ INTO V_VARIABLE2;
EXIT WHEN CURSOR_XYZ%NOTFOUND;
END LOOP;
CLOSE CURSOR_XYZ;
END LOOP;
CLOSE CURSOR_ABC;

Gul wrote:
i have a program like this
DECLARE
V_VARIABLE1 VARCHAR2(10);
CURSOR_ABC IS select...............;
BEGIN
OPEN CURSOR_ABC;
LOOP
FETCH CURSOR_ABC INTO V_VARIABLE1;
EXIT WHEN CURSOR_ABC%NOTFOUND;
WHAT IF I WANT TO INSERT ANOTHER SAME KINDA CURSOR LOOP HERE LIKE*
CURSOR_XYZ IS select...............;
BEGIN
OPEN CURSOR_XYZ;
LOOP
FETCH CURSOR_XYZ INTO V_VARIABLE2;
EXIT WHEN CURSOR_XYZ%NOTFOUND;
END LOOP;
CLOSE CURSOR_XYZ;
END LOOP;
CLOSE CURSOR_ABC;It is your code & you are free to implement what ever you desire.
CURSOR LOOPS are row by row & SLOW by SLOW!
How do I ask a question on the forums?
SQL and PL/SQL FAQ

Similar Messages

  • Using a Cursor in another cursor

    Hi Guys,
    I have declared a cursor in one of my program unit in forms 6i form, like this:
    Declare
    Cursor C1 is select employee_id, emp_name from employees;
    Begin
    End;
    Now i have to declare an other cursor that will be using the employee_id of the cursor C1.
    for example :
    Declare
    Cursor C1 is select employee_id, emp_name from employees;
    Cursor C2 is select C1.Employee_id, Employees.Age
    from C1, employees;
    Begin
    End;
    I dont think we can do this.... as it gives error in forms. What is the alternate how can i reference a cursor in another cursor??
    Kindly Help Pliz, Imran Baig

    Imran,
    you can do this. The way you try to read from a cursor is not correct because you treat a cursor like a table which it isn't. You have to loop through the parent cursor and then within this loop, loop the second cursor. Please see the PLSQL documentation on OTN on how to do this (its not that big of a deal).
    Frank

  • Create cursor from another cursor

    Hello,
    How do I create a cursor from the values of another cursor ?
    For Example,
    cursor c1
    select x, y from table 1;
    cursor c2
    select c1.x, c1.y, table 2.z
    from table 2
    where y := c1.y
    I get errors when I do this way. Can somebody help me out on this.
    Thanks
    Raj

    In this particular example, it's probably easiest to declare a single cursor that contains a join, i.e.
    cursor c1
    SELECT a.x, a.y, b.z
      FROM table1 a,
           table2 b
    WHERE a.y = b.yIf you really want to create the two cursors, though, you have to make sure that the first cursor is visible to the creation statement of the second. For example,
    for c1 in (select x, y from table1)
    loop
      for c2 in (select c1.x, c1.y, b.z from table2 b where b.y = c1.y)
      loop
      end loop;
    end loop;If you need more help, quoting the exact error an providing a snippet of the code you're using would be greatly helpful.
    Justin

  • Copying value from one cursor to another

    Hi,
    I have a problem while copying values from one cursor to another cursor.
    The code looks like below.
    PROCEDURE XYZ
                TransactionResultSet OUT NOCOPY types.ref_cursor,
    IS
                temp_cursor types.ref_cursor;
                wip_rec types.ref_cursor;
    BEGIN
    DECLARE
                    CURSOR temp_cursor IS
                SELECT ...........
    END;
    BEGIN     
        FOR wip_rec IN temp_cursor
        LOOP
        update tinsagr set something
        where {the condition}
            IF SQL%ROWCOUNT = 0 THEN
      dbms_output.put_line('this is test ');
            Fetch wip_rec into TransactionResultSet;
         END IF;
       END LOOP;so basically i want to iterate the "temp_cursor" and depending on the values i get it from here i shall update a table. Actually i want to exclude few records from "temp_cursor" and add it/copy rest of the records to "TransactionResultSet"
    That means say initially " temp_cursor" has 100 records and i updated 5 records in a table and same number of records should be excluded and rest should be added to the output cursor TransactionResultSet.
    How do i achieve it?
    while saving i am getting
    (1): PLS-00456: item 'WIP_REC' is not a cursor.
    Do any one has any idea what to do in such scenario?

    There are options like....
    SQL> CREATE OR REPLACE TYPE emp_obj AS OBJECT (ename VARCHAR2(50), dept NUMBER);
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE emp_tbl IS TABLE OF emp_obj;
      2  /
    Type created.
    SQL> set serverou on
    SP2-0158: unknown SET option "serverou"
    SQL> set serverout on
    SQL> DECLARE
      2    rc      sys_refcursor;
      3    v_ename emp.ename%TYPE;
      4    v_dept  emp.deptno%TYPE;
      5    ---End Of Local Varriable Declaration
      6    --Procedire declaration !
      7    PROCEDURE TEST_CUR(pi_out_ref_cur IN OUT sys_refcursor) IS
      8      emp_rec emp_tbl;
      9    BEGIN
    10      /* This BULK COLLECT can be done with explicit cursor,Ref Cursor
    11      with some simple modification, Here I have used implicit cursor! */
    12      SELECT emp_obj(ename, deptno) --Casting as the object
    13      BULK COLLECT
    14        INTO emp_rec
    15        FROM emp
    16       WHERE deptno = 10;
    17   
    18      dbms_output.put_line('Records selected are:');
    19      FOR i in 1 .. emp_rec.COUNT LOOP
    20        dbms_output.put_line(emp_rec(i).ename || '--' || emp_rec(i).dept);
    21      END LOOP;
    22      --Now we are filtering the record and may be doing some operation with each record.
    23      FOR i in 1 .. emp_rec.COUNT LOOP
    24        IF emp_rec(i).ename = 'KING' THEN
    25          --You can change this IF according to your need.
    26          emp_rec.DELETE(i);
    27        END IF;
    28      END LOOP;
    29      OPEN pi_out_ref_cur FOR
    30        SELECT * FROM TABLE(emp_rec); --Using the TYPE AS table.
    31    END TEST_CUR;
    32    /* Main execution or procedure calling section*/
    33  BEGIN
    34    --Actual calling
    35    TEST_CUR(rc);
    36    dbms_output.new_line;
    37    dbms_output.put_line('Now in Ref Cursor');
    38    dbms_output.put_line('****************');
    39    LOOP
    40      FETCH rc
    41        INTO v_ename, v_dept;
    42      dbms_output.put_line(v_ename || '--' || v_dept);
    43      EXIT WHEN rc%NOTFOUND;
    44    END LOOP;
    45 
    46  END;
    47  /
    Records selected are:
    CLARK--10
    KING--10
    MILLER--10
    Now in Ref Cursor
    CLARK--10
    MILLER--10
    MILLER--10
    PL/SQL procedure successfully completed.
    SQL>

  • How can I create cursors within the cursor?

    How can I create cursors within the cursor?
    Table1 2001 - 2007 data
    Account_no
    Account_eff_dt
    No_account_holder
    Num
    Seq_Num
    Value1
    Value2
    Table2_Historical (doesn't have Num as a field) 1990 - 2000 data
    Account_no
    Account_eff_dt
    No_account_holder
    Seq_Num
    Value1
    Value2
    Table3_06
    Account_no
    Account_eff_dt
    No_account_holder
    Num
    My result table should be:
    Table_result_06
    Account_no
    Account_eff_dt
    No_account_holder
    Num
    Value1_min (the minimum value for the minimum of record_sequence)
    Value2_max (the maximum value for the maximum of record_sequence)
    I have to get data from Table1 and Table2_Historical. If one account was open in 1998 and is still effective, the minimum value of that account is in the Table2_Historical.
    Let's say I open a cursor:
    cursor_first is
    select * from table3_06;
    open csr_first
    loop
    fetch cursor_first into
    v_Account_no
    v_Account_eff_dt
    v_No_account_holder
    v_Num
    EXIT WHEN csr_first%NOTFOUND;
    How can I open a second cursor from here that will get the Seq_Num from Table1
    csr_second
    select Seq_Num from Table1 where
    v_Account_no = Account_no
    v_Account_eff_dt <= Account_eff_dt
    v_No_account_holder=No_account_holder
    v_Num = Num
    How does it works???
    Thanks a lot

    Thanks so much for replying back. Here is what I am trying to do.
    I have to create a table for each year 2002, 2003, 2004, 2005, 2006 that has all the account numbers that are active each year plus some other characteristics.
    Let’s say I will create Table_result_06. This table will have the following fields. The account number, account effective date, Number of the account holder and the field Num (The primary key is a combination of all 4 fields), the beginning look of value 1 in 2006, the last look of value 1 in 2006.
    Table_result_06
    Account_no key
    Account_eff_dt key
    No_account_holder key
    Num key
    Value1_min (the minimum value for the minimum of record_sequence)
    Value2_max (the maximum value for the maximum of record_sequence)
    All the active account numbers with the Account_eff_dt, No_account_holder and Num are in the Table3. As such I can build a query that connects Table3 with table Table1 on all 4 fileds, Account_no, Account_eff_dt, No_account_holder, Num and find the Value1_min for the min of req_sequence in 2006 and Value1_max for the max of req_sequence in 2006. Here my problem starts.
    Table 1 doesn’t have a new entry if nothing has changed in the account. So if this account was open in 1993 and nothing has changed I don’t have an entry in 2006 but this doesn’t mean that this account doesn’t exist in 2006. So to find the minimum value I have to go back in 1993 and find the max and min for that year and that will be max and min in 2006 as well.
    As such I have to go to Table_2 historical and search for min and max. But this table doesn’t have the field NUM and if I match only on the Account_no, Account_eff_dt and No_account_holder I don’t get a unique record.
    So how can I connect all three tables, Table 1 for max and min, if it doesn’t find anything will go to table 2 find the two values and populate Table_result_06.
    Thanks so much again for your hep,

  • Automatic Cursor Movement in one Graph, in accordance to the cursor in another graph

    I am using two XY graphs each with 4 cursors. I want to assign each cursor of graph A to each cursor of graph B such that the corresponding cursors in graph B moves in accordance to the cursors in graph A.
     I have used Active cursor, Cursor.PosX and it works for one cursor. However when I use the same concept to change the active cursor value and faciliate the automatic movement for all cursors they do not work.
    Message Edited by Chathuri on 08-13-2009 06:26 AM
    Solved!
    Go to Solution.

    Hi,
    As requested I would like to post the solution as to how I tacked the problem. It was actually small mistake on my part. When I connect the two property nodes for each XY graphs I should connect ActiveCursor to ActiveCursor and Cursor.PosX to Cursor.PosX. What I did was connect the Active cursor of A graph to the cursor.index of B graph. I have attached a small screen shot of connecting the first cursor of A graph to the 1st cursor of B graph so that the cursor in B graph follows the cursor in A graph.
    In order to connect more cursors as in my case, the only change to be made is the change in the Acitve cursor constant to, 1,2,......
    Chathuri
    Attachments:
    CursorMovement.JPG ‏7 KB

  • How to Execute  sql query in PL/SQL ( a variable) with out using Cursor or REF cursor

    Hi
    I am building a dynamic query based on some conditions
    as an example
    v_query varchar2(2000);
    x1 varchar2(20);
    y1 varchar2(20);
    z1 varchar2(20);
    v_query := ' Select x,y,z into x1,y1,z1 From ... ';
    Is there any way to execute the query with out using cursor or ref cursor..
    Thanks
    Arun

    Both Tod and Eric provided valid responses given the format of the queory you supplied. Howver, if you want to use dynamic sql in either way, you need to be absolutely certain that your query will always only return a single row (e.g. SELECT COUNT(*) FROM mytable), because if it retuns more than one, your procedure will break unless you have an exception handler to handle either TOO_MANY_ROWS or OTHERS.
    If you want to pull in a lot of data without walking a cursor, you should look at the BULK COLLECT options.

  • Cursor value into cursor

    Hi all;
    help please. I want to create a cursor which takes value from another cursor so as to limit the rows, in same procedure. how can I do this?
    Thanks
    vg.

    vg,
    If I have understood your question right, the following might help : (Tried out in the SCOTT schema)
    DECLARE
    CURSOR cdept IS
    SELECT DEPTNO
    FROM DEPT;
    CURSOR cemp(dept varchar2) IS
    SELECT EMPNO, ENAME
    FROM EMP
    WHERE DEPTNO = dept;
    ldeptno dept.deptno%TYPE;
    lempno emp.empno%TYPE;
    lename emp.ename%TYPE;
    BEGIN
    OPEN cdept;
    LOOP
    FETCH cdept INTO ldeptno;
    EXIT WHEN cdept%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE('**** Department No : ' || ldeptno);
    OPEN cemp(ldeptno);
    LOOP
    FETCH cemp INTO lempno, lename;
    EXIT WHEN cemp%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(' ---- Employee No : ' || lempno || ' Name : ' || lename);
    END LOOP;
    CLOSE cemp;
    END LOOP;
    CLOSE cdept;
    END;
    Please let me know if this answers your question.

  • Converting cursor to ref cursor in Report builder pl/sql

    Hi,
    I am trying to use dynamic sql in My report 's pl/sql code.
    I can not use execute Immediate statement since this feature is not suppoerted at client side and i am doing the coding In my local mchine and running the report loaclly.......???
    Another way to use dynamic sql is by using dbms_sql package.
    Using dbms_sql to run a sql will give me a normal cursor as an output.
    Since in report builder pl/sql only ref cursor is allowed as a return type from a function........the problem i m facing is conversion of the cursor to ref cursor......
    in oracle 11g we have a built in function in dbms_sql package that can be used for the conversion....
    i m using oracle 10 g where the above mentioned feature is not available............
    Please give some way to resolve this issue............!!!!!!!!!!!!
    Thanks in Advance.....!!!!!!!
    Abhishant

    You may use some stored procedures that will take full advantage of dynamic SQL. Make a stored proc that inserts rows in a global temporary table. You will call that stored proc in the afterpform trigger. And you will have the report querry select from the temporary table populated by the stored proc.
    I did some things like that.
    HTH

  • How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    unless i'm missing something, i think you got mixed up, this is easy google for walk throughs
    i'm assuming this is the new 3tb tc AC or 'tower' shape, if so, its wifi will run circles around your at&t device
    unplug the at&t box for a minute and plug it back in
    factory reset your tc - unplug it, hold down reset and keep holding while you plug it back in - only release reset when amber light flashes in 10-20s
    connect the tc to your at&t box via eth in the wan port, wait 1 minute, open airport utility look in 'other wifi devices' to setup the tc
    create a new wifi network (give it a different name than your at&t one) and put the tc in bridge mode (it may do this automatically for you, but you should double check) under the 'network' tab
    login to your at&t router and disable wifi on it
    add new clients to the new wifi network, and point your Macs to the time machine for backups

  • Can  you move your notes from one iphone to another and how?

    Can you move your notes from one iphone to another and how?

    You can do this a couple ways.  If you are using MobileMe, notes is one of the options for synchronization and that would be automatic.  Another way is to backup your iphone to iTunes, this backs up essentially all the information on your phone (except for music) and if you restore the other iphone to the image of the original your notes will be transfered.

  • I have registered products under multiple appleIDs. I would like to merge them into a another. How?

    I have registered products under multiple appleIDs. I would like to merge them into a another. How?

    You do not.
    I have multiple Apple IDs. Is there a way for me to merge them into a single Apple ID?
    Apple IDs cannot be merged. You should use your preferred Apple ID from now on, but you can still access your purchased items such as music, movies, or software using your other Apple IDs.
    Frequently asked questions about Apple ID
    Or maybe this since it is not clear what you want to do
    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device

  • I have no problems copying iMovie Events from one Mac to another, however, how can I copy iMovie Projects from one Mac to another?

    I have no problems copying iMovie Events from one Mac to another, however, how can I copy iMovie Projects from one Mac to another?  Any help will be appreciated.  Thank you.

    This should give you some good insight, I'd probably store them on an External HD on the old machine and then just drag and drop to the new machine.
    https://discussions.apple.com/docs/DOC-4141

  • I need to move 1000 photos from one library to another. How do I do that and keep the ratings and dates they were created?

    I need to move 1000 photos from one library to another. How do I do that and keep the ratings and dates they were created? I tried exporting them, but it loses all info. Also, how do I move the quicktime movies from one iphoto library to another? They were exported as jpgs

    Add both libraries to iPhoto Library Manager.  Then select the events or albums that you want to copy from library A  and drag them to library B in iPLM.
    This video shows the process:
    OT

  • I re-installed XP and kept the old program files on another drive, how can I transfer my bookmarks list to the new Firefox ?

    I re-installed XP and kept the old program files on another drive, how can I transfer my bookmarks list to the new Firefox ?
    I tried shifting the Profile folder contents from the old to the new, that seemed to work but I kept getting a message that my security was affected and that the problem could be in that folder so I shifted it back.

    Hello Kencrews,
    When you connect the iPod to the computer and iTunes is authorized for your Apple ID, then you will get a prompt to transfer the purchases from the device to the computer. Keep in mind this will only transfer purchased items from the iTunes Store.
    Here is a helpful article to assist getting that done.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    http://support.apple.com/kb/ht1848
    Regards,
    Sterling

Maybe you are looking for

  • Resetting a password

    I recently got a 2nd generation itouch on craigslist, and the person I bought it from didn't tell me it was passworded his post is now gone and I can not get him My question is there a way to set it back to its original settings so I can create my ow

  • Error Handling on RFC - XI - File Scenario

    I have an R/3 RFC -> XI -> FILE scenario that works, but does not adequately handle the error of my R/3 to XI connection being down. The RFC call is async since I was under the impression that I had to do a "to file" scenario that way.     CALL FUNCT

  • Can no longer convert DOC to PDF

    I've been using Acrobat 6 Pro for years to convert Microsoft Word (2003) DOCs to PDFs.  After a power failure, some of my Adobe products had to be repaired and re-registered.  On the other side of this procedure, I seem to have lost the conversion fu

  • IMac and iPad air vs MacBook Pro retina

    Hello there With the new products being released, I was wondering what combination people have gone for. At present I have an iPhone 5s, iPad 2 and windows laptop but really want a mac. What combination have others gone for?? I am considering iMac an

  • 9.2 database can SQL desired output achived more simple and effective way?

    Hi, In a table I am having one column with varchar2(1000) storing data for e.g. !!:FA:/Field Value A1!!:FB:/Field Value of B1!!:FC:/Field Value of C1!!:FD:/Field Value of D1!!:FE:/Field Value of E1!! !!:FA:/Field Value of A2:FE:/Field Value of E2!! !