Dropping objects without ORA-00942 errors
This procedure enables to drop any object in an Oracle database if you have the rights for it. It will give you a clean spool file -- no ORA-00942 messages -- when installing or dropping objects where you are not sure if they exist or not. This produces no error messages even if the object does not exist. It may be useful when looking for any other errors in big spool files after installing hundreds of tables, views, packages, etc. The script has been tested on v. 8.1.7.
create or replace procedure dropObject (ownerName in varchar2, objectName in varchar2) is
cursor C1 is
select 'DROP '||o.object_type||' "' || o.owner || '"."' || o.object_name ||'"'
from sys.dba_objects o
where o.owner = ownerName
and o.object_name = objectName ;
DDL_CURSOR integer;
ddl_statement varchar2(500);
BEGIN
DDL_CURSOR := dbms_sql.open_cursor;
OPEN C1;
LOOP
FETCH C1 INTO ddl_statement;
EXIT WHEN C1%NOTFOUND;
dbms_sql.parse(DDL_CURSOR, ddl_statement, dbms_sql.native);
END LOOP;
dbms_sql.close_cursor(DDL_CURSOR);
CLOSE C1;
END;
This was first published in February 2004
Disclaimer:
Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.
Join the conversationComment
Share
Comments
Results
Contribute to the conversation