Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    1

    Unanswered: Insert Statment using max value for Start

    Hi,

    I'm trying to get this to work and I'm having trouble..any ideas why

    insert into key_inventory (inventory_year,status,key_department,serial_numbe r,key_id, id)
    create sequence seq_id
    minvalue 1
    start with max(key_id)+1 from key_inventory
    cache 9999999999999999999;
    select
    '2009',
    'P',
    '041500',

    ka.serial_number,ka.key_id, seq_id.nextval


    from key_access ka

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    where does one statement end & the next begins?

    using sqlplus along with CUT & PASTE, show us what you do & how Oracle responds.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    You have to create the sequence FIRST.

    Code:
    select max(id)
    from key_inventory;
    
    
    create sequence seq_id
    minvalue 1
    start with the_max_value+1
    cache 20;
    
    insert into key_inventory (inventory_year,status,key_department,serial_number,key_id, id)
    select '2009','P','041500',ka.serial_number,ka.key_id, seq_id.nextval
    from key_access ka;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

Posting Permissions

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