Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generate and Auto Number

Status
Not open for further replies.

kophjager

Technical User
Oct 24, 2002
31
0
0
US
Forgive me for the probably dumb question, but I have a table that has a five digit number value in it. Is there a way to autoincrement it by one when I insert a new record, in this new records number value. I'm sorry I am quite new to this and learning as I go along so any help would be appreciated. Thank you.

 
yes surely you can have a numeric value generated automatically by a database object called sequence. For this you have to use the standard syntax of

create sequence seq1
start with 1
increment by 1;

This will create a value each time incremented by one. Whenyou want to use this in the table,
you can access it with 'extval' psudocolumn as below.

insert into tabname values(seq1.nextvale,......restof the values);

You can refer to documentation for a detailed info about sequences adn the rest of the clauses while creating the sequences. Also pls refer to data dictionry called user_equences after you create the seqence.

Remember that the sequence values can not be rolledback so if yourollback the insert stmt, you are loosing a value. Next time sequence will generate next value.

hope this helps

abhivyakti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top