DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: use sequence to update column in cursor for loop

  1. #1
    Join Date
    Jun 2000
    Location
    dumfries,va,usa
    Posts
    227
    Hi,
    I'm using a cursor for loop to update a column on a table with a sequence. This update should occur for all rows on the table. I get the error message :(sequence not allowed here). Is there a better way update the column with the sequence value? Please see code below:

    /* This will update the sales_person_id of the salesperson table with a unique number from the sequence */

    declare

    cursor sales_id is
    select sales_person_id from om_sales_person for update;

    BEGIN

    for c_sales_id in sales_id loop
    UPDATE om_sales_person
    SET sales_person_id = (select om_sales_person_id_seq.nextval from dual);
    WHERE CURRENT OF sales_id;

    END LOOP;
    commit;
    END;
    /
    leonard905
    leonard905@yahoo.com

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Just change your update statement inside the loop:


    UPDATE om_sales_person
    SET sales_person_id = om_sales_person_id_seq.nextval
    WHERE CURRENT OF sales_id;
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  3. #3
    Join Date
    Jun 2000
    Location
    dumfries,va,usa
    Posts
    227
    Thanks. It worked.
    leonard905
    leonard905@yahoo.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width