session - Incrementing Oracle Sequence by certain amount -


i programming windows application (in qt 4.6) - @ point - inserts number of datasets between 1 , around 76000 oracle (10.2) table. application has retrieve primary keys, or @ least primary key range, sequence. store ids in list used batch execution of prepared query.

(note: triggers shall not used, , sequence used other tasks well)

in order avoid calling sequence x times, increment sequence x instead.

what have found out far, following code possible in procedure:

alter sequence my_sequence increment x;  select my_sequence.curval + 1, my_sequence.nextval   v_first_number, v_last_number   dual;  alter sequence my_sequence increment 1; 

i have 2 major concerns though:

  1. i have read alter sequence produces implicit commit. mean transaction started windows application commited? if so, can somehow avoid it?
  2. is concept multi-user proof? or following thing happen:

    sequence @ 10,000 session sets increment 2,000 session selects 10,001 first , 12,000 last session b sets increment 5,000 session sets increment 1 session b selects 12,001 first , 12,001 last session b sets increment 1 

    even if procedure rather quick, not unlikely in application 2 different users cause procedure called simultaneously

altering sequence in scenario bad idea. particularly in multiuser environment. you'll transaction committed , several "race condition" data bugs or integrity errors. appropriate if had legacy data alredy imported , want insert new data ids sequence. may alter sequence move currval max existing ...

it seems me here want generate ids sequence. need not done

select seq.nextval l_variable dual; insert table (id, ...) values (l_variable, ....); 

you can use sequence directly in insert:

insert table values (id, ...) values (seq.nextval, ....); 

and optionally assigned value by

insert table values (id, ...) values (seq.nextval, ....) returning id l_variable; 

it possible bulk operations execbatch. either creating ids or returning them. not sure right syntax in java lines

insert table values (id, ...) values (seq.nextval, ....) returning id bulk collect l_cursor; 

and you'll given resultset browse assigned numbers.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -