I'm running some test to migrate data from one database to another and for that i need to delete and recreate same tables, views and other stuff. So what is the SQL statement(s) in Oracle to wipe everything (delete Tables, Views, Sequences, Functions, Procedures, etc.). I know that I can use "DROP" but sometimes that's not convenient enough.
Thanks
The easiest way would be to drop the schema the objects are associated to:
DROP USER [schema name] CASCADE
Nuke it from orbit - it's the only way to be sure ;)
For the script you provided, you could instead run those queries without having to generate the intermediate script using the following anonymous procedure:
BEGIN
--Bye Views!
FOR i IN (SELECT uv.view_name
FROM USER_VIEWS uv) LOOP
EXECUTE IMMEDIATE 'drop view '|| i.view_name ||'';
END LOOP;
--Bye Sequences!
FOR i IN (SELECT us.sequence_name
FROM USER_SEQUENCES us) LOOP
EXECUTE IMMEDIATE 'drop sequence '|| i.sequence_name ||'';
END LOOP;
--Bye Tables!
FOR i IN (SELECT ut.table_name
FROM USER_TABLES ut) LOOP
EXECUTE IMMEDIATE 'drop table '|| i.table_name ||' CASCADE CONSTRAINTS ';
END LOOP;
--Bye Procedures/Functions/Packages!
FOR i IN (SELECT us.name,
us.type
FROM USER_SOURCE us
WHERE us.type IN ('PROCEDURE', 'FUNCTION', 'PACKAGE')
GROUP BY us.name, us.type) LOOP
EXECUTE IMMEDIATE 'drop '|| i.type ||' '|| i.name ||'';
END LOOP;
--Bye Synonyms!
FOR i IN (SELECT ut.synonym_name
FROM USER_SYNONYMS us
WHERE us.synonym_name NOT LIKE 'sta%'
AND us.synonym_name LIKE 's_%') LOOP
EXECUTE IMMEDIATE 'drop synonym '|| i.synonym_name ||'';
END LOOP;
END;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With