<?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"
	>
<channel>
	<title>Comments on: How to avoid ORA errors when dropping inexistant objects</title>
	<atom:link href="http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html/feed/" rel="self" type="application/rss+xml" />
	<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html</link>
	<description>Oracle Certified Master</description>
	<pubDate>Mon, 01 Dec 2008 20:43:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-4166</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Wed, 27 Jun 2007 09:24:35 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-4166</guid>
		<description>yes, it is a good approach too ;-)</description>
		<content:encoded><![CDATA[<p>yes, it is a good approach too <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giorgio Arata</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-4164</link>
		<dc:creator>Giorgio Arata</dc:creator>
		<pubDate>Wed, 27 Jun 2007 08:59:59 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-4164</guid>
		<description>Hi All,

If the problem was about voiding the errors spitted out at the SQL*PLUS command prompt, another approach would be to write an anonymous PL/SQL block where you deal with any exception adopting the "EXCEPTION WHEN OTHERS THEN NULL;" deprecated code style. 

OTN forum comes into help to give an example of the technique.
Read Paul M. thread reply if you want to go this way dropping DB objects.

Link follow..

http://forums.oracle.com/forums/thread.jspa?messageID=1910163&#38;tstart=0

Best regards, GA.</description>
		<content:encoded><![CDATA[<p>Hi All,</p>
<p>If the problem was about voiding the errors spitted out at the SQL*PLUS command prompt, another approach would be to write an anonymous PL/SQL block where you deal with any exception adopting the &#8220;EXCEPTION WHEN OTHERS THEN NULL;&#8221; deprecated code style. </p>
<p>OTN forum comes into help to give an example of the technique.<br />
Read Paul M. thread reply if you want to go this way dropping DB objects.</p>
<p>Link follow..</p>
<p><a href="http://forums.oracle.com/forums/thread.jspa?messageID=1910163&amp;tstart=0" rel="nofollow">http://forums.oracle.com/forums/thread.jspa?messageID=1910163&amp;tstart=0</a></p>
<p>Best regards, GA.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2386</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Thu, 10 May 2007 07:43:10 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2386</guid>
		<description>mdinh is right too, Pierre meant, if &lt;i&gt;DROP ANY TABLE&lt;/i&gt; is granted to a role</description>
		<content:encoded><![CDATA[<p>mdinh is right too, Pierre meant, if <i>DROP ANY TABLE</i> is granted to a role</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2385</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Thu, 10 May 2007 07:40:33 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2385</guid>
		<description>Pierre,
this is right, I could imagine something like :

&lt;code&gt;drop.sql&lt;/code&gt;
&lt;i&gt;drop table &#038;1;&lt;/i&gt;

&lt;code&gt;nodrop.sql&lt;/code&gt;
&lt;i&gt;-- do nothing&lt;/i&gt;

&lt;code&gt;
SQL&gt; create table t( x number);

Table created.

SQL&gt; col to_drop_or_not_to_drop new_v _drop nopri
SQL&gt; select decode(count(*),0,'nodrop','drop')
  2    to_drop_or_not_to_drop from all_tables
  3    where owner='AUDBA' and table_name='T';
&lt;/code&gt;
&lt;i&gt;
SQL&#62; @ &#038;_drop AUDBA.T
old   1: drop table &#038;1
new   1: drop table AUDBA.T
&lt;/i&gt;&lt;code&gt;
Table dropped.

SQL&gt; select decode(count(*),0,'nodrop','drop')
  2    to_drop_or_not_to_drop from all_tables
  3    where owner='AUDBA' and table_name='T';




SQL&gt; @ &#038;_drop AUDBA.T
SQL&gt; 
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Pierre,<br />
this is right, I could imagine something like :</p>
<p><code>drop.sql</code><br />
<i>drop table &#038;1;</i></p>
<p><code>nodrop.sql</code><br />
<i>&#8211; do nothing</i></p>
<p><pre><code>
SQL&gt; create table t( x number);

Table created.

SQL&gt; col to_drop_or_not_to_drop new_v _drop nopri
SQL&gt; select decode(count(*),0,&#039;nodrop&#039;,&#039;drop&#039;)
&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;to_drop_or_not_to_drop from all_tables
&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;where owner=&#039;AUDBA&#039; and table_name=&#039;T&#039;;
</code></pre><br />
<i><br />
SQL&gt; @ &#038;_drop AUDBA.T<br />
old   1: drop table &#038;1<br />
new   1: drop table AUDBA.T<br />
</i><pre><code>
Table dropped.

SQL&gt; select decode(count(*),0,&#039;nodrop&#039;,&#039;drop&#039;)
&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;to_drop_or_not_to_drop from all_tables
&nbsp;&nbsp;3&nbsp;&nbsp;&nbsp;&nbsp;where owner=&#039;AUDBA&#039; and table_name=&#039;T&#039;;

SQL&gt; @ &amp;_drop AUDBA.T
SQL&gt; 
</code></pre></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Reitschuster</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2382</link>
		<dc:creator>Karl Reitschuster</dc:creator>
		<pubDate>Thu, 10 May 2007 07:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2382</guid>
		<description>You must be carful using this contruct.

The Statement CREATE OR REPLACE VIEW ...
is atomic - it's assured that the same object is replaced.

With the additional for construct it is not. Thinking of scripts with a lot of table ddl and the copy/paste technology ;-)

A better approach would be something like this :

BEGIN util_ddl.create_or_replace_table('CREATE TABLE ...'); END;
/

The procedure extracts the tables name and drops it if it's exist.
The only thing is : it this allowd in production environment?
because the Tables DDL is processed in a black box?

cheers
Karl</description>
		<content:encoded><![CDATA[<p>You must be carful using this contruct.</p>
<p>The Statement CREATE OR REPLACE VIEW &#8230;<br />
is atomic - it&#8217;s assured that the same object is replaced.</p>
<p>With the additional for construct it is not. Thinking of scripts with a lot of table ddl and the copy/paste technology <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>A better approach would be something like this :</p>
<p>BEGIN util_ddl.create_or_replace_table(&#8217;CREATE TABLE &#8230;&#8217;); END;<br />
/</p>
<p>The procedure extracts the tables name and drops it if it&#8217;s exist.<br />
The only thing is : it this allowd in production environment?<br />
because the Tables DDL is processed in a black box?</p>
<p>cheers<br />
Karl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mdinh</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2353</link>
		<dc:creator>mdinh</dc:creator>
		<pubDate>Wed, 09 May 2007 20:19:24 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2353</guid>
		<description>You do not need drop privileges to drop objects owned by you.

SQL&#62; create user mdinh identified by m default tablespace sysaux;

User created.

SQL&#62; alter user mdinh quota unlimited on sysaux;

User altered.

SQL&#62; create role apps;

Role created.

SQL&#62; grant create session, create table to apps;

Grant succeeded.

SQL&#62; grant apps to mdinh;

Grant succeeded.

SQL&#62; create table mdinh.t(id int);

Table created.

SQL&#62; connect mdinh/m
Connected.
SQL&#62; exec for f in (select 1 from user_tables where table_name='T') -
loop execute immediate 'drop table t cascade constraints'; -
end loop;
create table t(x number);
&#62; &#62;
PL/SQL procedure successfully completed.

SQL&#62;
Table created.

SQL&#62; desc t;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 X                                                  NUMBER

SQL&#62;</description>
		<content:encoded><![CDATA[<p>You do not need drop privileges to drop objects owned by you.</p>
<p>SQL&gt; create user mdinh identified by m default tablespace sysaux;</p>
<p>User created.</p>
<p>SQL&gt; alter user mdinh quota unlimited on sysaux;</p>
<p>User altered.</p>
<p>SQL&gt; create role apps;</p>
<p>Role created.</p>
<p>SQL&gt; grant create session, create table to apps;</p>
<p>Grant succeeded.</p>
<p>SQL&gt; grant apps to mdinh;</p>
<p>Grant succeeded.</p>
<p>SQL&gt; create table mdinh.t(id int);</p>
<p>Table created.</p>
<p>SQL&gt; connect mdinh/m<br />
Connected.<br />
SQL&gt; exec for f in (select 1 from user_tables where table_name=&#8217;T') -<br />
loop execute immediate &#8216;drop table t cascade constraints&#8217;; -<br />
end loop;<br />
create table t(x number);<br />
&gt; &gt;<br />
PL/SQL procedure successfully completed.</p>
<p>SQL&gt;<br />
Table created.</p>
<p>SQL&gt; desc t;<br />
 Name                                      Null?    Type<br />
 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
 X                                                  NUMBER</p>
<p>SQL&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mdinh</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2352</link>
		<dc:creator>mdinh</dc:creator>
		<pubDate>Wed, 09 May 2007 20:04:57 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2352</guid>
		<description>Thanks!  Just figured it out and found you already replied.

Alternatively,

exec for f in (select 1 from user_tables where table_name='T') -
loop execute immediate 'drop table t cascade constraints'; -
end loop;
create table t(x number);</description>
		<content:encoded><![CDATA[<p>Thanks!  Just figured it out and found you already replied.</p>
<p>Alternatively,</p>
<p>exec for f in (select 1 from user_tables where table_name=&#8217;T') -<br />
loop execute immediate &#8216;drop table t cascade constraints&#8217;; -<br />
end loop;<br />
create table t(x number);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Laurent Schneider</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2351</link>
		<dc:creator>Laurent Schneider</dc:creator>
		<pubDate>Wed, 09 May 2007 20:00:14 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2351</guid>
		<description>:-(
exec must be in one line, sorry for all those formatting annoyances...

about drop granted to a role, i will have a look</description>
		<content:encoded><![CDATA[<p> <img src='http://laurentschneider.com/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /><br />
exec must be in one line, sorry for all those formatting annoyances&#8230;</p>
<p>about drop granted to a role, i will have a look</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mdinh</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2350</link>
		<dc:creator>mdinh</dc:creator>
		<pubDate>Wed, 09 May 2007 19:57:13 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2350</guid>
		<description>What version of Oracle does this work for?

I tried it for 10gR2 and got the errors:

SQL&#62; select 1 from user_tables where
  table_name='T'  2  ;

         1
----------
         1

SQL&#62; exec for f in (select 1 from user_tables where
  table_name='T') loop execute immediate
  'drop table t cascade constraints'; end loop
create table t(x number);
BEGIN for f in (select 1 from user_tables where; END;

                                              *
ERROR at line 1:
ORA-06550: line 1, column 47:
PL/SQL: ORA-00936: missing expression
ORA-06550: line 1, column 16:
PL/SQL: SQL Statement ignored
ORA-06550: line 1, column 48:
PLS-00103: Encountered the symbol ";" when expecting one of the following:
loop


SQL&#62; SP2-0734: unknown command beginning "table_name..." - rest of line ignored.
SQL&#62; SP2-0734: unknown command beginning "'drop tabl..." - rest of line ignored.
SQL&#62; create table t(x number)
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object


SQL&#62;</description>
		<content:encoded><![CDATA[<p>What version of Oracle does this work for?</p>
<p>I tried it for 10gR2 and got the errors:</p>
<p>SQL&gt; select 1 from user_tables where<br />
  table_name=&#8217;T&#8217;  2  ;</p>
<p>         1<br />
&#8212;&#8212;&#8212;-<br />
         1</p>
<p>SQL&gt; exec for f in (select 1 from user_tables where<br />
  table_name=&#8217;T') loop execute immediate<br />
  &#8216;drop table t cascade constraints&#8217;; end loop<br />
create table t(x number);<br />
BEGIN for f in (select 1 from user_tables where; END;</p>
<p>                                              *<br />
ERROR at line 1:<br />
ORA-06550: line 1, column 47:<br />
PL/SQL: ORA-00936: missing expression<br />
ORA-06550: line 1, column 16:<br />
PL/SQL: SQL Statement ignored<br />
ORA-06550: line 1, column 48:<br />
PLS-00103: Encountered the symbol &#8220;;&#8221; when expecting one of the following:<br />
loop</p>
<p>SQL&gt; SP2-0734: unknown command beginning &#8220;table_name&#8230;&#8221; - rest of line ignored.<br />
SQL&gt; SP2-0734: unknown command beginning &#8220;&#8216;drop tabl&#8230;&#8221; - rest of line ignored.<br />
SQL&gt; create table t(x number)<br />
             *<br />
ERROR at line 1:<br />
ORA-00955: name is already used by an existing object</p>
<p>SQL&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre Forstmann</title>
		<link>http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2347</link>
		<dc:creator>Pierre Forstmann</dc:creator>
		<pubDate>Wed, 09 May 2007 19:36:31 +0000</pubDate>
		<guid isPermaLink="false">http://laurentschneider.com/wordpress/2007/05/how-to-avoid-ora-errors-when-dropping-inexistant-objects.html#comment-2347</guid>
		<description>This solution requires that the object owner will have the CREATE/DROP privilege directly granted (not through a role).  Unfortunately  this is not always the case.</description>
		<content:encoded><![CDATA[<p>This solution requires that the object owner will have the CREATE/DROP privilege directly granted (not through a role).  Unfortunately  this is not always the case.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
