• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about add the id number according the existing sequence

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an existing sequence called TOPICSEQ in the database(oracle), there is a table called t_topic whose id is incremented using this TOPICSEQ. The detail of this seq is created like following
CREATE SEQUENCE TOPICSEQ
INCREMENT BY 1
START WITH 1001 MAXVALUE 9999 MINVALUE 1
NOCYCLE CACHE 20 NOORDER;
It works fine when populating the db with scripts, but when inserting the data using the format like this:
String insertTopic="INSERT INTO T_TOPIC VALUES (TOPICSEQ.NEXTVAL,?,0,'unchecked')";
the last topicID is 1006 in the table before I insert the data , after the insertion, the ID becomes 1021. I don't know what the hell it is and I thought it should follow the sequence since I specified the name of the sequence.

Please, just a week I have to submit my project. Any idea will be appreciated. Thanks a lot!
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jian,
The "cache 20" tells oracle to reserve groups of 20 ids at a time. When your script ran, it probably got allocated 1000-1020. Then, when you ran using a different client (jdbc) it got from the next available group. Thus 1021.
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic