Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: create sequence with subqueryfor starting value?
In article <XUFt7.19689$Xz1.4335830_at_news1.rdc1.md.home.com>, "Neil says...
>
>I would like to write a simple script to create a sequence and assign it a
>starting value of the current high value of the related column, something
>like this:
>
>create sequence my_seq start with ( select max(unique_key) from my_table; );
>
>No matter what I do, Oracle comes back with 'not a number'.
>
>Is there a way to do this without dynamically creating and running a script
>file?
>
>Thanks,
>Neil
>
>
If you are using sqlplus as your scripting environment:
column max_val new_val S
select max(unique_key)+1 max_val from my_table;
create sequence my_seq start with &S;
will do it....
-- Thomas Kyte (tkyte@us.oracle.com) http://asktom.oracle.com/ Expert one on one Oracle, programming techniques and solutions for Oracle. http://www.amazon.com/exec/obidos/ASIN/1861004826/ Opinions are mine and do not necessarily reflect those of Oracle CorpReceived on Sun Sep 30 2001 - 12:02:16 CDT