Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get max sequence number when some record exists in data base table

1001979Apr 18 2013 — edited Apr 18 2013
Hi,

I need to create sequence such a way that it should starts from max value already exists in table.

Example:
I have table like below:

ID NAME
1 A
2 B
3 C
4 D


Now when creating sequence it should start from 5 but I should't hard code STARTS WITH 5 in the create sequence. Is there any way to do this without hard code the max value in the sequence. It should automatically take the max + 1 value for next data when I insert.


CREATE SEQUENCE TEST_SEQ.NEXTVAL
START WITH [Max + 1 val from the table]
MAXVALUE 9999999999999999999999999999
MINVALUE 1
NOCYCLE
CACHE 20
NOORDER;


Thanks.....

Edited by: 998976 on Apr 18, 2013 4:37 AM

Edited by: 998976 on Apr 18, 2013 4:38 AM
This post has been answered by Frank Kulash on Apr 18 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2013
Added on Apr 18 2013
2 comments
800 views