Unix Technical Forum

drop and recreate sequence from sql

This is a discussion on drop and recreate sequence from sql within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hi. I can't seem to figure out the correct syntax here. This should be usable on oracle 9i up. ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 12:17 PM
Jeff Kish
 
Posts: n/a
Default drop and recreate sequence from sql

Hi.

I can't seem to figure out the correct syntax here. This should
be usable on oracle 9i up.

I have a sequence and table that is a bit messed up and I'd like
to supply an sql script someone could run to fix things.
Bacially

declare
myMax number;
begin
select max (table_id) + 1 into somevar from mytable into myMax;
drop sequence mytable_table_id_seq;
create sequence mytable_table_id_seq startwith myMax;

end;


but it does not like the drop and create.

Can someone tell me the best way to get this working?

thanks
Jeff Kish
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 12:17 PM
DA Morgan
 
Posts: n/a
Default Re: drop and recreate sequence from sql

Jeff Kish wrote:
> Hi.
>
> I can't seem to figure out the correct syntax here. This should
> be usable on oracle 9i up.
>
> I have a sequence and table that is a bit messed up and I'd like
> to supply an sql script someone could run to fix things.
> Bacially
>
> declare
> myMax number;
> begin
> select max (table_id) + 1 into somevar from mytable into myMax;
> drop sequence mytable_table_id_seq;
> create sequence mytable_table_id_seq startwith myMax;
>
> end;
>
>
> but it does not like the drop and create.
>
> Can someone tell me the best way to get this working?
>
> thanks
> Jeff Kish


It is a bad idea even when done with good syntax.

You must use dynamic SQL to execute DDL.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 12:17 PM
William Robertson
 
Posts: n/a
Default Re: drop and recreate sequence from sql

On Feb 12, 8:03 pm, Jeff Kish <jeff.k...@mro.com> wrote:
> Hi.
>
> I can't seem to figure out the correct syntax here. This should
> be usable on oracle 9i up.
>
> I have a sequence and table that is a bit messed up and I'd like
> to supply an sql script someone could run to fix things.
> Bacially
>
> declare
> myMax number;
> begin
> select max (table_id) + 1 into somevar from mytable into myMax;
> drop sequence mytable_table_id_seq;
> create sequence mytable_table_id_seq startwith myMax;
>
> end;
>
> but it does not like the drop and create.
>
> Can someone tell me the best way to get this working?
>
> thanks
> Jeff Kish


Rather than dropping and recreating, you should adjust the increment,
get sequence.nextval, and set the increment back to what it was. This
is a bit trickier but avoids invalidating dependant code and losing
grants etc.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com