Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: create sequence with subqueryfor starting value?

Re: create sequence with subqueryfor starting value?

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 30 Sep 2001 10:02:16 -0700
Message-ID: <9p7j6o01fbp@drn.newsguy.com>


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 Corp 
Received on Sun Sep 30 2001 - 12:02:16 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US