<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Changing the Current Value of Oracle Sequences</title>
	<atom:link href="http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/</link>
	<description>because I don't believe in life before coffee...</description>
	<lastBuildDate>Wed, 28 Oct 2009 06:44:36 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Serge</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-367992</link>
		<dc:creator>Serge</dc:creator>
		<pubDate>Wed, 19 Mar 2008 17:05:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-367992</guid>
		<description>It works like that :

declare
sqlstmt varchar2(200);
begin
for x in (select sequence_name from user_sequences) loop
sqlstmt := &#039;alter sequence &#039;&#124;&#124;x.sequence_name&#124;&#124;&#039; increment by 10&#039;;
execute immediate sqlstmt;
sqlstmt := &#039;declare retval number(10); begin select &#039;&#124;&#124;x.sequence_name&#124;&#124;&#039;.nextval into retval from dual; commit; end;&#039;;
execute immediate sqlstmt;
sqlstmt := &#039;alter sequence &#039;&#124;&#124;x.sequence_name&#124;&#124;&#039; increment by 1&#039;;
execute immediate sqlstmt;
end loop;
end;

I know this is not very clean code, but it seems that a nextval does not work in a pure select statement in execute immediate function.</description>
		<content:encoded><![CDATA[<p>It works like that :</p>
<p>declare<br />
sqlstmt varchar2(200);<br />
begin<br />
for x in (select sequence_name from user_sequences) loop<br />
sqlstmt := &#8216;alter sequence &#8216;||x.sequence_name||&#8217; increment by 10&#8242;;<br />
execute immediate sqlstmt;<br />
sqlstmt := &#8216;declare retval number(10); begin select &#8216;||x.sequence_name||&#8217;.nextval into retval from dual; commit; end;&#8217;;<br />
execute immediate sqlstmt;<br />
sqlstmt := &#8216;alter sequence &#8216;||x.sequence_name||&#8217; increment by 1&#8242;;<br />
execute immediate sqlstmt;<br />
end loop;<br />
end;</p>
<p>I know this is not very clean code, but it seems that a nextval does not work in a pure select statement in execute immediate function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-367138</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Tue, 19 Feb 2008 19:31:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-367138</guid>
		<description>I have a situation where using a procedure may be beneficial:

We have development databases for all of our developers.  Each developer gets a sandbox to play in.  Some of them play with more sand than others, so their sequence numbers are higher.  We have a base data set that gets updated periodically that the developers use to refresh their data periodically to a known, good state.  This, unfortunately, results in occasional tromping of sequence numbers.  I have tried to build a procedure to step them, but it still does not work.

declare
  sqlstmt varchar2(200);
begin
  for x in (select sequence_name from user_sequences) loop
    sqlstmt := &#039;alter sequence &#039;&#124;&#124;x.sequence_name&#124;&#124;&#039; increment by 100&#039;;
    execute immediate (sqlstmt);
    sqlstmt := &#039;select &#039;&#124;&#124;x.sequence_name&#124;&#124;&#039;.nextval from dual&#039;;
    execute immediate (sqlstmt);
    sqlstmt := &#039;alter sequence &#039;&#124;&#124;x.sequence_name&#124;&#124;&#039; increment by 1&#039;;
    execute immediate (sqlstmt);
  end loop;
end;

This doesn&#039;t do anything to the sequences, so I am relegated to running the scripts individually.</description>
		<content:encoded><![CDATA[<p>I have a situation where using a procedure may be beneficial:</p>
<p>We have development databases for all of our developers.  Each developer gets a sandbox to play in.  Some of them play with more sand than others, so their sequence numbers are higher.  We have a base data set that gets updated periodically that the developers use to refresh their data periodically to a known, good state.  This, unfortunately, results in occasional tromping of sequence numbers.  I have tried to build a procedure to step them, but it still does not work.</p>
<p>declare<br />
  sqlstmt varchar2(200);<br />
begin<br />
  for x in (select sequence_name from user_sequences) loop<br />
    sqlstmt := &#8216;alter sequence &#8216;||x.sequence_name||&#8217; increment by 100&#8242;;<br />
    execute immediate (sqlstmt);<br />
    sqlstmt := &#8217;select &#8216;||x.sequence_name||&#8217;.nextval from dual&#8217;;<br />
    execute immediate (sqlstmt);<br />
    sqlstmt := &#8216;alter sequence &#8216;||x.sequence_name||&#8217; increment by 1&#8242;;<br />
    execute immediate (sqlstmt);<br />
  end loop;<br />
end;</p>
<p>This doesn&#8217;t do anything to the sequences, so I am relegated to running the scripts individually.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Emmons</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-336982</link>
		<dc:creator>Jon Emmons</dc:creator>
		<pubDate>Thu, 29 Nov 2007 02:07:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-336982</guid>
		<description>Not a bad idea Kevin, but this is something I hope people aren&#039;t doing too often so I don&#039;t consider it a good candidate for a procedure.  Sequences aren&#039;t really intended to be reset all the time and if you find you need to you might want to consider using something other than a sequence.</description>
		<content:encoded><![CDATA[<p>Not a bad idea Kevin, but this is something I hope people aren&#8217;t doing too often so I don&#8217;t consider it a good candidate for a procedure.  Sequences aren&#8217;t really intended to be reset all the time and if you find you need to you might want to consider using something other than a sequence.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevin</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-335397</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Mon, 26 Nov 2007 17:21:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-335397</guid>
		<description>nice work, but how would you make this into a procedure so that you could pass in the sequence name and the value you want it to be changed to?</description>
		<content:encoded><![CDATA[<p>nice work, but how would you make this into a procedure so that you could pass in the sequence name and the value you want it to be changed to?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anydoby</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-320172</link>
		<dc:creator>anydoby</dc:creator>
		<pubDate>Wed, 07 Nov 2007 09:14:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-320172</guid>
		<description>thanks a lot</description>
		<content:encoded><![CDATA[<p>thanks a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nikhil</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-35871</link>
		<dc:creator>Nikhil</dc:creator>
		<pubDate>Wed, 17 Jan 2007 10:36:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-35871</guid>
		<description>Thanks, it was correctly mentioned.</description>
		<content:encoded><![CDATA[<p>Thanks, it was correctly mentioned.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amy</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-507</link>
		<dc:creator>Amy</dc:creator>
		<pubDate>Mon, 24 Apr 2006 16:09:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-507</guid>
		<description>This was very helpful!  Your site is great.</description>
		<content:encoded><![CDATA[<p>This was very helpful!  Your site is great.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-67</link>
		<dc:creator>Jon</dc:creator>
		<pubDate>Mon, 14 Nov 2005 13:21:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-67</guid>
		<description>Thanks ko!  This is a great tip!</description>
		<content:encoded><![CDATA[<p>Thanks ko!  This is a great tip!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ko</title>
		<link>http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/comment-page-1/#comment-65</link>
		<dc:creator>ko</dc:creator>
		<pubDate>Mon, 14 Nov 2005 07:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.lifeaftercoffee.com/2005/10/20/changing-the-current-value-of-oracle-sequences/#comment-65</guid>
		<description>You can specify a negative increment to decrease the sequence.

alter sequence id_sequence increment by -142900;

More info: 
http://www.jlcomp.demon.co.uk/faq/resetseq.html</description>
		<content:encoded><![CDATA[<p>You can specify a negative increment to decrease the sequence.</p>
<p>alter sequence id_sequence increment by -142900;</p>
<p>More info:<br />
<a href="http://www.jlcomp.demon.co.uk/faq/resetseq.html" rel="nofollow">http://www.jlcomp.demon.co.uk/faq/resetseq.html</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
