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

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Dropping & re-Creating Sequences in PL/SQL

RE: Dropping & re-Creating Sequences in PL/SQL

From: Alex Hillman <alex_hillman_at_physia.com>
Date: Mon, 3 Jul 2000 16:24:21 -0400
Message-Id: <10547.111138@fatcity.com>


This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.

------_=_NextPart_001_01BFE52C.ABEF5D90
Content-Type: text/plain;

        charset="iso-8859-1"

How would you reset the sequence? From Oracle 8i SQL reference "to restart the sequence from the different number you must drop and recreate the sequence".

Alex Hillman

-----Original Message-----
From: Jared Still [mailto:jkstill_at_bcbso.com] Sent: Thursday, June 29, 2000 2:09 PM
To: Multiple recipients of list ORACLE-L Subject: RE: Dropping & re-Creating Sequences in PL/SQL

I'll take it a step further and ask 'Why are you dropping the sequence?'

Just reset it to the value you need.

Jared

On Wed, 28 Jun 2000, Larry G. Elkins wrote:

> While DDL statements aren't directly supported in PL/SQL, since the person
> is on 8.1.6 (8i Release 2), there isn't (normally) a need to use DBMS_SQL
in
> this case. Dynamic SQL is still needed, but, the old DBMS_SQL construct is
> not. The "execute immediate", as the person spoke of, sounds like it
should
> work just fine. There are still cases where the old DBMS_SQL stuff is
> preferable; but, creating and dropping sequences should be able to be done
> with "execute immediate" without resorting to DBMS_SQL:
>
> SQL> begin
> 2 execute immediate 'create sequence xxx';
> 3 end;
> 4 /
>
> PL/SQL procedure successfully completed.
>
> SQL> select xxx.nextval from dual;
>
> NEXTVAL
> ----------
> 1
>
> SQL> begin
> 2 execute immediate 'drop sequence xxx';
> 3 end;
> 4 /
>
> PL/SQL procedure successfully completed.
>
> SQL> select xxx.nextval from dual;
> select xxx.nextval from dual
> *
> ERROR at line 1:
> ORA-02289: sequence does not exist
>
> So, what type of errors are you seeing? When you use the execute immediate
> with the sequence stuff in-line, you say it doesn't compile. When you
assign
> the command to a variable, then, reference the variable in your execute
> immdediate, you say it compiles. Does it work then?
>
> I bring this up because I can do what you are trying do. This is on an NT
> workstation with SP5. And using the newer dynamic SQL approach of execute
> immediate like you did.
>
> There could be other things in play here (permissions and roles versus a
> direct priv thing, maybe bugs). I have no idea. I have no problem doing
what
> you want to do.
>
> Regards,
>
> Larry G. Elkins
> The Elkins Organization Inc.
> elkinsl_at_flash.net
> 214.954.1781
>
> -----Original Message-----
> Turner
> Sent: Wednesday, June 28, 2000 10:25 AM
> To: Multiple recipients of list ORACLE-L
>
>
> Since those particular statements are considered DDL statements, you need
> to use the DBMS_SQL commands to execute them within a pl/sql package.
>
> Christine Turner
> Database Administrator
> IPS-Sendero
> Scottsdale, Arizona
> Phone: (800) 321-6899 ext. 3286
> Fax: (480) 946-8224
> E-mail: christine.turner_at_ips-sendero.com
>
>
>
> -----Original Message-----
> From: Mike & Martha [SMTP:mmrose_at_home.com]
> Sent: Wednesday, June 28, 2000 7:09 AM
> To: Multiple recipients of list ORACLE-L
> Subject: Dropping & re-Creating Sequences in PL/SQL
>
>
> Hello,
>
> I've been unable to get the following commands to 'compile' in a PL/SQL
> package body in Oracle 8.1.6 Version 2 (8i with NTS 4.0 SP 6a):
>
> DROP SEQUENCE sequence_name;
>
> CREATE SEQUENCE sequence_name;
>
> I get errors like the commands aren't recognized.
>
> When I try to use EXECUTE IMMEDIATE 'DROP SEQUENCE sequence_name'
>
> I still get compile errors.
>
> I can compile when I use to following:
>
> Temp VARCHAR2(60);
>
> Temp := 'DROP SEQUENCE sequence_name';
>
> EXECUTE IMMEDIATE Temp;
>
> I would really appreciate some help here!
>
> Michael Rose
> mmrose_at_home.com
>
> --
> Author: Larry G. Elkins
> INET: elkinsl_at_flash.net
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
>

Jared Still
Certified Oracle DBA and Part Time Perl Evangelist ;-) Regence BlueCross BlueShield of Oregon
jkstill_at_bcbso.com - Work - preferred address jkstill_at_teleport.com - private

-- 
Author: Jared Still
  INET: jkstill_at_bcbso.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

------_=_NextPart_001_01BFE52C.ABEF5D90
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2448.0">
<TITLE>RE: Dropping &amp; re-Creating Sequences in PL/SQL</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>How would you reset the sequence? From Oracle 8i SQL =
reference &quot;to restart the sequence from the different number you =
must drop and recreate the sequence&quot;.</FONT></P>

<P><FONT SIZE=3D2>Alex Hillman</FONT>
</P>

<P><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Jared Still [<A =
HREF=3D"mailto:jkstill_at_bcbso.com">mailto:jkstill_at_bcbso.com</A>]</FONT>
<BR><FONT SIZE=3D2>Sent: Thursday, June 29, 2000 2:09 PM</FONT>
<BR><FONT SIZE=3D2>To: Multiple recipients of list ORACLE-L</FONT>
<BR><FONT SIZE=3D2>Subject: RE: Dropping &amp; re-Creating Sequences in =
PL/SQL</FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=3D2>I'll take it a step further and ask 'Why are you =
dropping the sequence?'</FONT>
</P>

<P><FONT SIZE=3D2>Just reset it to the value you need.</FONT>
</P>

<P><FONT SIZE=3D2>Jared</FONT>
</P>

<P><FONT SIZE=3D2>On Wed, 28 Jun 2000, Larry G. Elkins wrote:</FONT>
</P>

<P><FONT SIZE=3D2>&gt; While DDL statements aren't directly supported =
in PL/SQL, since the person</FONT>
<BR><FONT SIZE=3D2>&gt; is on 8.1.6 (8i Release 2), there isn't =
(normally) a need to use DBMS_SQL in</FONT>
<BR><FONT SIZE=3D2>&gt; this case. Dynamic SQL is still needed, but, =
the old DBMS_SQL construct is</FONT>
<BR><FONT SIZE=3D2>&gt; not. The &quot;execute immediate&quot;, as the =
person spoke of, sounds like it should</FONT>
<BR><FONT SIZE=3D2>&gt; work just fine. There are still cases where the =
old DBMS_SQL stuff is</FONT>
<BR><FONT SIZE=3D2>&gt; preferable; but, creating and dropping =
sequences should be able to be done</FONT>
<BR><FONT SIZE=3D2>&gt; with &quot;execute immediate&quot; without =
resorting to DBMS_SQL:</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; SQL&gt; begin</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 2&nbsp; execute immediate 'create =
sequence xxx';</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 3&nbsp; end;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 4&nbsp; /</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; PL/SQL procedure successfully completed.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; SQL&gt; select xxx.nextval from dual;</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp; NEXTVAL</FONT>
<BR><FONT SIZE=3D2>&gt; ----------</FONT>
<BR><FONT =
SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
1</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; SQL&gt; begin</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 2&nbsp; execute immediate 'drop =
sequence xxx';</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 3&nbsp; end;</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; 4&nbsp; /</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; PL/SQL procedure successfully completed.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; SQL&gt; select xxx.nextval from dual;</FONT>
<BR><FONT SIZE=3D2>&gt; select xxx.nextval from dual</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
*</FONT>
<BR><FONT SIZE=3D2>&gt; ERROR at line 1:</FONT>
<BR><FONT SIZE=3D2>&gt; ORA-02289: sequence does not exist</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; So, what type of errors are you seeing? When =
you use the execute immediate</FONT>
<BR><FONT SIZE=3D2>&gt; with the sequence stuff in-line, you say it =
doesn't compile. When you assign</FONT>
<BR><FONT SIZE=3D2>&gt; the command to a variable, then, reference the =
variable in your execute</FONT>
<BR><FONT SIZE=3D2>&gt; immdediate, you say it compiles. Does it work =
then?</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; I bring this up because I can do what you are =
trying do. This is on an NT</FONT>
<BR><FONT SIZE=3D2>&gt; workstation with SP5. And using the newer =
dynamic SQL approach of execute</FONT>
<BR><FONT SIZE=3D2>&gt; immediate like you did.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; There could be other things in play here =
(permissions and roles versus a</FONT>
<BR><FONT SIZE=3D2>&gt; direct priv thing, maybe bugs). I have no idea. =
I have no problem doing what</FONT>
<BR><FONT SIZE=3D2>&gt; you want to do.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Regards,</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Larry G. Elkins</FONT>
<BR><FONT SIZE=3D2>&gt; The Elkins Organization Inc.</FONT>
<BR><FONT SIZE=3D2>&gt; elkinsl_at_flash.net</FONT>
<BR><FONT SIZE=3D2>&gt; 214.954.1781</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=3D2>&gt; Turner</FONT>
<BR><FONT SIZE=3D2>&gt; Sent: Wednesday, June 28, 2000 10:25 AM</FONT>
<BR><FONT SIZE=3D2>&gt; To: Multiple recipients of list ORACLE-L</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Since those particular statements are =
considered DDL statements, you need</FONT>
<BR><FONT SIZE=3D2>&gt; to use the DBMS_SQL commands to execute them =
within a pl/sql package.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Christine Turner</FONT>
<BR><FONT SIZE=3D2>&gt; Database Administrator</FONT>
<BR><FONT SIZE=3D2>&gt; IPS-Sendero</FONT>
<BR><FONT SIZE=3D2>&gt; Scottsdale, Arizona</FONT>
<BR><FONT SIZE=3D2>&gt; Phone:&nbsp; (800) 321-6899 ext. 3286</FONT>
<BR><FONT SIZE=3D2>&gt; Fax:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (480) =
946-8224</FONT>
<BR><FONT SIZE=3D2>&gt; E-mail:&nbsp; =
christine.turner_at_ips-sendero.com</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; -----Original Message-----</FONT>
<BR><FONT SIZE=3D2>&gt; From: Mike &amp; Martha =
[SMTP:mmrose_at_home.com]</FONT>
<BR><FONT SIZE=3D2>&gt; Sent: Wednesday, June 28, 2000 7:09 AM</FONT>
<BR><FONT SIZE=3D2>&gt; To:&nbsp;&nbsp; Multiple recipients of list =
ORACLE-L</FONT>
<BR><FONT SIZE=3D2>&gt; Subject:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dropping =
&amp; re-Creating Sequences in PL/SQL</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Hello,</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; I've been unable to get the following commands =
to 'compile' in a PL/SQL</FONT>
<BR><FONT SIZE=3D2>&gt; package body in Oracle 8.1.6 Version 2 (8i with =
NTS 4.0 SP 6a):</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; DROP SEQUENCE sequence_name;</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; CREATE SEQUENCE sequence_name;</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; I get errors like the commands aren't =
recognized.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; When I try to use EXECUTE IMMEDIATE 'DROP =
SEQUENCE sequence_name'</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; I still get compile errors.</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; I can compile when I use to following:</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Temp VARCHAR2(60);</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Temp :=3D 'DROP SEQUENCE sequence_name';</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; EXECUTE IMMEDIATE Temp;</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; I would really appreciate some help =
here!</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Michael Rose</FONT>
<BR><FONT SIZE=3D2>&gt; mmrose_at_home.com</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; -- </FONT>
<BR><FONT SIZE=3D2>&gt; Author: Larry G. Elkins</FONT>
<BR><FONT SIZE=3D2>&gt;&nbsp;&nbsp; INET: elkinsl_at_flash.net</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; Fat City Network Services&nbsp;&nbsp;&nbsp; -- =
(858) 538-5051&nbsp; FAX: (858) 538-5051</FONT>
<BR><FONT SIZE=3D2>&gt; San Diego, California&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp; -- Public Internet access / Mailing Lists</FONT>
<BR><FONT SIZE=3D2>&gt; =
--------------------------------------------------------------------</FO=
NT>
<BR><FONT SIZE=3D2>&gt; To REMOVE yourself from this mailing list, send =
an E-Mail message</FONT>
<BR><FONT SIZE=3D2>&gt; to: ListGuru_at_fatcity.com (note EXACT spelling =
of 'ListGuru') and in</FONT>
<BR><FONT SIZE=3D2>&gt; the message BODY, include a line containing: =
UNSUB ORACLE-L</FONT>
<BR><FONT SIZE=3D2>&gt; (or the name of mailing list you want to be =
removed from).&nbsp; You may</FONT>
<BR><FONT SIZE=3D2>&gt; also send the HELP command for other =
information (like subscribing).</FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
</P>
<BR>

<P><FONT SIZE=3D2>Jared Still</FONT>
<BR><FONT SIZE=3D2>Certified Oracle DBA and Part Time Perl =
Evangelist&nbsp; ;-)</FONT>
<BR><FONT SIZE=3D2>Regence BlueCross BlueShield of Oregon</FONT>
<BR><FONT SIZE=3D2>jkstill_at_bcbso.com - Work - preferred address</FONT>
<BR><FONT SIZE=3D2>jkstill_at_teleport.com - private</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>-- </FONT>
<BR><FONT SIZE=3D2>Author: Jared Still</FONT>
<BR><FONT SIZE=3D2>&nbsp; INET: jkstill_at_bcbso.com</FONT>
</P>

<P><FONT SIZE=3D2>Fat City Network Services&nbsp;&nbsp;&nbsp; -- (858) =
538-5051&nbsp; FAX: (858) 538-5051</FONT>
<BR><FONT SIZE=3D2>San Diego, =
California&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Public Internet =
access / Mailing Lists</FONT>
<BR><FONT =
SIZE=3D2>---------------------------------------------------------------=
-----</FONT>
<BR><FONT SIZE=3D2>To REMOVE yourself from this mailing list, send an =
E-Mail message</FONT>
<BR><FONT SIZE=3D2>to: ListGuru_at_fatcity.com (note EXACT spelling of =
Received on Mon Jul 03 2000 - 15:24:21 CDT

Original text of this message

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