File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Oracle/OAS and the fly likes sequence in oracle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "sequence in oracle" Watch "sequence in oracle" New topic

sequence in oracle

siva sankar
Ranch Hand

Joined: Jul 13, 2006
Posts: 68

I created a sequence as following;

create sequence seq1;

Now,i created a table with the following structure.

create table tab1(eno number,ename varchar2(10));

Now,i want the eno in tab1 to refer the sequence seq1.I can't able to get this.Please,suugest me a solution on how i have to do this.

Thanks in Advance,
Siva Sankar
Liju Cherian
Ranch Hand

Joined: Mar 17, 2006
Posts: 44
You will have to use TRIGGERS if you'd like to insert the value automatically, while inserting a new row; else you will have to explicitly fetch the next sequence and insert it along with the other values.

Hope this helps....

"What's in a name? That which we call a rose by any other name would smell just as sweet."<br />(William Shakespeare, Romeo and Juliet, Act II, Scene II)
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Yes usually you will have an insert statement that includes getting the nextval from your sequence table.


insert into tab1 fields(eno, ename) values (seq1.nextval, "somevalue");


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Carol Enderlin
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
use seq1.nextval in the insert

If that's not enough detail, try:

dang, mark beat me to it and included the sql!
[ November 08, 2006: Message edited by: Carol Enderlin ]
I agree. Here's the link:
subject: sequence in oracle
It's not a secret anymore!