File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to create sequence for my table in Oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to create sequence for my table in Oracle" Watch "How to create sequence for my table in Oracle" New topic
Author

How to create sequence for my table in Oracle

whongwei
Greenhorn

Joined: Dec 12, 2000
Posts: 7
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

Joined: Nov 02, 2000
Posts: 195
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

Joined: Dec 12, 2000
Posts: 7
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

Joined: Jan 07, 1999
Posts: 6920
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.

Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
whongwei
Greenhorn

Joined: Dec 12, 2000
Posts: 7
Frank:
can you tell me how do I change my name.
Brian Nice
Ranch Hand

Joined: Nov 02, 2000
Posts: 195
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

Joined: Jan 07, 1999
Posts: 6920
To change your name just choose a different one when you log in, and stop using the old one.
Hongwei
Greenhorn

Joined: Dec 20, 2000
Posts: 2
Ok, Frank. I have register another one. Thanks .
cheers
Hongwei
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
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

Joined: Dec 21, 2000
Posts: 22
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

Joined: Jan 07, 1999
Posts: 6920
Many thanks. I hope you return here many times, and continue to both enjoy the Java Ranch and find it useful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create sequence for my table in Oracle