Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 4th, 2004, 12:12 PM
Farha Farha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 8 Farha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 0
Generating id using nextval sequence

Hi!
I have created a vb application with a oracle backend. To create a primary key 'customerid' i have used the nextval sequence.The problem is this that whenever I close the application and restart it and insert the 'customerid' the value inserted is not the value next to the last value i.e if last value before closing was 13 then after restarting the values inserted will be inorder 21,22...
Can any one tell me what can be the problem?
Thankz

Reply With Quote
  #2  
Old November 5th, 2004, 08:20 AM
ksagar_k ksagar_k is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 ksagar_k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Check with your sequence creation. If 'cache n' is specified then oracle will try to generate the 'n' sequences well in advance and put in the cache so that requests can be served immediately. These cached sequences will be lost on the server restart.

This may be the reason. Do let me know if there is something else with it ..
sagar

Reply With Quote
  #3  
Old November 8th, 2004, 12:12 PM
Farha Farha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 8 Farha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 0
Hi!i am sorry for replying late as i was busy with my project submission.
actually, this is what i have done
create sequence CustomerIDSequence
Start with 1
Increment by 1
NoMinValue
NoMaxValue
NoCycle
NoCache
Is there a mistake somewhere?as u c there is 'nocache' specified.is it because of 'nocycle'

Reply With Quote
  #4  
Old November 8th, 2004, 12:18 PM
Farha Farha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 8 Farha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 0
Hi!i am sorry for replying late as i was busy with my project submission.
actually, this is what i have done
create sequence CustomerIDSequence
Start with 1
Increment by 1
NoMinValue
NoMaxValue
NoCycle
NoCache
Is there a mistake somewhere?as u c there is 'nocache' specified.is it because of 'nocycle'?

Reply With Quote
  #5  
Old November 9th, 2004, 05:53 PM
RodP RodP is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 4 RodP User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I had this problem with Oracle forms. Since a form's default status is NEW, the ID auto-incremented even though nothing was being done. I don't know about VB, but consider using a form-level procedure to create the ID based on a specific user action.

Reply With Quote
  #6  
Old November 11th, 2004, 07:36 AM
Farha Farha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 8 Farha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 0
hmmmmm.i'm already using a procedure in oracle to call the sequence.it has 2 be something else

Reply With Quote
  #7  
Old November 11th, 2004, 08:51 AM
hedge hedge is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2002
Posts: 692 hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level)hedge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 23 h 15 m 53 sec
Reputation Power: 19
I've also had this issue when generating invoice #'s, when the data was rolled back it would cause a jump in the invoice#'s. Is it possible that a rollback is causing your issue?

A nextval on a sequence is not rolled back so that could cause jumps in your numbers if the inserts are rolled back.

Reply With Quote
  #8  
Old November 11th, 2004, 09:09 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 17 m 10 sec
Reputation Power: 48
FWIW - we have a gigantic Oracle DB with sequences the in the 15 digit range.
We don't worry if a number is missing. Our customer numbers are 10 digits, and we are missing soem numbers. Again, it is not a problem.

If sequential numbers are an absolute requirement, with no missing values, you will have to maintain a table that has one row for each customer number - pretty much like what the forms response (RodP) is saying above - roll your own. You cannot use a sequence.

Reply With Quote
  #9  
Old November 11th, 2004, 12:04 PM
hasnain hasnain is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 3 hasnain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Query instead of sequence

you can also use query instead of Sequence like:
Sequence is used as
insert into table(id) values(my_seq.nextval);

but you can do this
Select max(id)+1 into v_seq from table;
insert into table(id) values(v_id);

Query works great as compare to sequence because sequence can generate Gaps but query never.

Hope that will help you.

Reply With Quote
  #10  
Old November 11th, 2004, 03:14 PM
shammat shammat is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 1,005 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 11 h 53 m 39 sec
Reputation Power: 67
Code:
Query works great as compare to sequence because sequence can generate Gaps but query never.

In general it not matter if there are gaps in the sequence or not. If your application relies on that, then rethink your design. An artificial primary key (that's what a sequence number is) should never carry any further information.

Btw: if you are using the max() approach you should lock the table to avoid problems with parallel inserts or use another mechanism that ensures that two processes will never use the same ID, which can happen with the solution you use.

Reply With Quote
  #11  
Old November 13th, 2004, 12:03 PM
Farha Farha is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 8 Farha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 0
i understand what u guys are saying.the problem is this that
the people for whom i am designing this increment the customer id sequentially eg. cr1,cr2...now if i don't use a sequence 2 increment n do it thru the form then i have 2 use .recordcount +1 .the problem occurs when i delete a id ie the next id generated would be be the no.of records +1. but the problem occurs when v delete the last id then the id generated is the same as before but that id should not now be repeated.....so now what else can be done

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Generating id using nextval sequence


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT