Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create sequence for my table in Oracle

 
whongwei
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, All:
Can any one help me how to create the sequence for my table in Orcale, just like the Access have the autonum, it will automated increase by themself.
Thanks for any help.
hongwei
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have my oracle book with me, but if I recall it's:
create sequence [sequence_name] start with [number] increment by [increment]
Then you can access the sequence with:
select sequence_name.nextval from dual;
HTH
Brian
 
whongwei
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Brian:
Thanks for the repling, now I know how to create sequence, but how do I use it for one particular table, I don't know, hope if you can give me some guide.
cheers
hongwei
Originally posted by Brian Nice:
I don't have my oracle book with me, but if I recall it's:
create sequence [sequence_name] start with [number] increment by [increment]
Then you can access the sequence with:
select sequence_name.nextval from dual;
HTH
Brian

 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note that The Java Ranch has a naming policy, described here and "whongwei" is not a valid name. Please choose one which meets the requirements.
Thanks.
 
whongwei
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank:
can you tell me how do I change my name.
 
Brian Nice
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TO use it for one particular table, after you have created the sequence, get the next value of the sequence. Get a database connection and create a Statement, then execute the query:
long sequenceNum = 0;
Statement st = ...
ResultSet rs = st.executeQuery("Select sequence_name.nextval from dual");
if (rs.next() ) sequenceNum = rs.getLong(1);
Now you have the value stored in a variable that you can use later in your Java program for whatever you need
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To change your name just choose a different one when you log in, and stop using the old one.
 
Hongwei
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, Frank. I have register another one. Thanks .
cheers
Hongwei
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for changing your login name, but I'm afrid your new name is not valid either!
I'm sorry if I didn't explain it properly, but the naming policy, described at http://www.javaranch.com/name.jsp requires a name with two words. It's not that "Whongwei" or "Hongwei" are not your name, it's just that they only have one word. Do you also have another name such as a family name, or can you split the "Whongwei" into two or more names?
I'm sorry to be so picky, but this naming posicly was set up by the owner of the Java Ranch site. Thanks again for all your efforts.
 
Eric Wang
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank:
Now the instruction for name is very clear, so I hope I got me right name, Eric Wang. How is it? So you can delete the two name Whongwei and Hongwei for me, I am using the same email hongwei@engineer.com. Thanks.
It is time to said Merry Christmas to you. A Card just for you, I have take two days to do it. Hope you like it.
http://myhome.asia1.com/home/h/hongwei/fromeric.html
Cheers
Eric
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks. I hope you return here many times, and continue to both enjoy the Java Ranch and find it useful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic