How to delete all stored procedures in the database

I have to build and rebuild a a database. That often times involves deleting all tables and stored procedures in the database. Pretty tedious process because I have to delete each object one by one. Can someone give me a script that I can use to delete all of the tables, and another script to delete all of the stored procedures in Oracle. That would really save me some time building and rebuilding.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you want to get rid of everything, why not simply drop the database and then create a new one?

But, if you really want to purge tables and procedures something like this should work.

You can adjust the object_type IN list to include other things like VIEW, FUNCTION, PACKAGE, TYPE, etc.

    v_ddl   VARCHAR2(1000);
    FOR x
        IN (SELECT owner, object_name, object_type
              FROM dba_objects
             WHERE owner IN ('your_schema1', 'your_schema2')
               AND owner NOT IN ('SYS', 'SYSTEM')  -- white list above is sufficient, this is mostly as a reminder
               AND object_type IN ('TABLE', 'PROCEDURE'))
            v_ddl := 'drop ' || x.object_type || ' "' || x.object_owner || '"."' || x.object_name || '"';

            EXECUTE IMMEDIATE v_ddl;
            WHEN OTHERS
                RAISE;  --- remove this line if you want to continue after an error

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
why not stop the database
delete the files at OS level

and then recreate the database ?

i'm assuming this is a typical qas refresh ?

you could also backup the production and restore it as qas
slightwv (䄆 Netminder) Commented:
I was thinking it would even be simpler:  drop the schema cascade.  If you drop all tables and procedures, what would be kept?  Functions and packages?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.